Go Up to Defining And Undefining Macros Index
You can undefine a macro using the #undef directive. #undef detaches any previous token sequence from the macro identifier; the macro definition has been forgotten, and the macro identifier is undefined. No macro expansion occurs within #undef lines.
The state of being defined or undefined turns out to be an important property of an identifier, regardless of the actual definition. The #ifdef and #ifndef conditional directives, used to test whether any identifier is currently defined or not, offer a flexible mechanism for controlling many aspects of a compilation.
After a macro identifier has been undefined, it can be redefined with #define, using the same or a different token sequence.
Attempting to redefine an already defined macro identifier will result in a warning unless the new definition is exactly the same token-by-token definition as the existing one. The preferred strategy where definitions might exist in other header files is as follows:
#ifndef BLOCK_SIZE #define BLOCK_SIZE 512 #endif
The middle line is bypassed if
BLOCK_SIZE is currently defined; if
BLOCK_SIZE is not currently defined, the middle line is invoked to define it.
No semicolon (;) is needed to terminate a preprocessor directive. Any character found in the token sequence, including semicolons, will appear in the macro expansion. The token sequence terminates at the first non-backslashed new line encountered. Any sequence of whitespace, including comments in the token sequence, is replaced with a single-space character.