Learn C Programming

Lesson 2 of 8 · The Preprocessor, Headers and Multi File Builds

Module 15 · The Preprocessor, Headers and Multi File Builds

Macros: define, Function Macros and Their Traps

ProReading

Zara tests edge cases first. She wrote a MAX macro with every bracket in place, then handed it i++. With i at 5 and j at 3, she expected biggest = 5, i = 6.

Checking what this lesson needs for you…

What is inside Macros: define, Function Macros and Their Traps

  1. A macro is text the preprocessor pastes
  2. Trap 1: an argument without parentheses
  3. Trap 2: a body without outer parentheses
  4. Trap 3: an argument evaluated twice
  5. Trap 4: a macro of several statements
  6. A static inline function does the same job
  7. Two operators only macros have: # and ##
  8. An X-macro keeps two tables in step