You are previewing Code Complete, Second Edition.

Code Complete, Second Edition

Cover of Code Complete, Second Edition by Steve McConnell Published by Microsoft Press

Macro Routines and Inline Routines

Routines created with preprocessor macros call for a few unique considerations. The following rules and examples pertain to using the preprocessor in C++. If you're using a different language or preprocessor, adapt the rules to your situation.


Even if your language doesn't have a macro preprocessor, you can build your own. For details, see Building Your Own Programming Tools.

Fully parenthesize macro expressions. Because macros and their arguments are expanded into code, be careful that they expand the way you want them to. One common problem lies in creating a macro like this one:

Example 7-10. C++ Example of a Macro That Doesn't Expand Properly

#define Cube( a ) a*a*a

If you pass this macro nonatomic ...

The best content for your career. Discover unlimited learning on demand for around $1/day.