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.

Cross-Reference

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 ...

Get Code Complete, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.