Developer --> Technical Publications
PATH  Mac OS X Server Documentation > The GNU C Preprocessor

The GNU C Preprocessor

Previous | Contents | Next

Undefining Macros

To undefine a macro means to cancel its definition. This is done with the #undef command. #undef is followed by the macro name to be undefined.

Like definition, undefinition occurs at a specific point in the source file, and it applies starting from that point. The name ceases to be a macro name, and from that point on it's treated by the preprocessor as if it had never been a macro name.

For example,

#define FOO 4
x = FOO;
#undef FOO
x = FOO;

expands into

x = 4;
x = FOO;

In this example, FOO must be a variable or function as well as (temporarily) a macro, in order for the result of the expansion to be valid C code.

The same form of #undef command will cancel definitions with arguments or definitions that don't expect arguments. The #undef command has no effect when used on a name not currently defined as a macro.


The GNU C Preprocessor

Previous | Contents | Next