cpp: Undefining and Redefining Macros
1
1 3.8 Undefining and Redefining Macros
1 ====================================
1
1 If a macro ceases to be useful, it may be "undefined" with the '#undef'
1 directive. '#undef' takes a single argument, the name of the macro to
1 undefine. You use the bare macro name, even if the macro is
1 function-like. It is an error if anything appears on the line after the
1 macro name. '#undef' has no effect if the name is not a macro.
1
1 #define FOO 4
1 x = FOO; ==> x = 4;
1 #undef FOO
1 x = FOO; ==> x = FOO;
1
1 Once a macro has been undefined, that identifier may be "redefined"
1 as a macro by a subsequent '#define' directive. The new definition need
1 not have any resemblance to the old definition.
1
1 However, if an identifier which is currently a macro is redefined,
1 then the new definition must be "effectively the same" as the old one.
1 Two macro definitions are effectively the same if:
1 * Both are the same type of macro (object- or function-like).
1 * All the tokens of the replacement list are the same.
1 * If there are any parameters, they are the same.
1 * Whitespace appears in the same places in both. It need not be
1 exactly the same amount of whitespace, though. Remember that
1 comments count as whitespace.
1
1 These definitions are effectively the same:
1 #define FOUR (2 + 2)
1 #define FOUR (2 + 2)
1 #define FOUR (2 /* two */ + 2)
1 but these are not:
1 #define FOUR (2 + 2)
1 #define FOUR ( 2+2 )
1 #define FOUR (2 * 2)
1 #define FOUR(score,and,seven,years,ago) (2 + 2)
1
1 If a macro is redefined with a definition that is not effectively the
1 same as the old one, the preprocessor issues a warning and changes the
1 macro to use the new definition. If the new definition is effectively
1 the same, the redefinition is silently ignored. This allows, for
1 instance, two different headers to define a common macro. The
1 preprocessor will only complain if the definitions do not match.
1