In practical terms there are two types of macros. “Object-like” macros take no arguments, while “function-like” macros can be defined to accept arguments so that they look and act like function calls. The next section gives the syntax for both kinds of macros. Because macros do not generate actual function calls, you can make programs faster by replacing function calls with macros. However, macros can create problems if you do not define and use them with care. You may have to use parentheses in macro definitions with arguments to preserve the proper precedence in an expression. Also, macros may not handle expressions with side effects as a function would. See the examples on topic , “The #define Directive” for more information.
When the preprocessor encounters a macro, the macro is replaced by the macro body. If the macro accepts arguments, the arguments following the macro name are substituted for parameters in the macro body. The process of replacing a macro call with the processed copy of the body is called “expansion” of the macro call. Macros are not expanded recursively.
Microsoft Specific
Macro expansions of up to 6K are permitted.¨Preprocessing expands macros in all nondirective lines and in parts of some directives that are not skipped as part of a conditional compilation. Therefore, if a macro expands into something that looks like a preprocessor command, that command is not recognized by the preprocessor. (See topic for information on conditional compilation.)
Once you have defined a manifest constant or a macro, you cannot redefine it to a different value without first removing the original definition. However, you can redefine a manifest constant or a macro with exactly the same definition. This is useful if you have the same macro in several include files.
The #undef directive removes the definition of a manifest constant or a macro. Once you have removed the definition, you can redefine a manifest constant to a different value or a macro to a different statement without causing a compiler warning to be generated.
Using inline functions instead of function-like macros can be more reliable since parameters are type-checked, all expressions passed to a function are evaluated, and all side effects are complete prior to entry into the function. This is not necessarily true for macros. See information on __inline on topic .