A preprocessor transforms source code before compilation. Its textual macro substitution can reduce repetitive typing, but it also means the compiler processes code different from what was written, complicating errors and debugging. section 5.2
Common macro mistakes include:
- Using an untyped PI macro, which can produce an unintended type. section 5.2
- Defining SQUARE(n) as n * n, which substitutes expressions repeatedly and can change results or evaluate side effects twice. section 5.2
- Ending a FOR macro's loop header with a semicolon, creating a null loop body and leaving the following statement to run once. section 5.2
Replace macros with C++ constructs
Use a typed const double for PI, a template function for square, an explicit for loop, and bool with false rather than value-like macros. These forms make the generated behavior visible and prevent accidental repeated substitution.


