How can you check to see whether a symbol is defined?


You can use the #ifdef and #ifndef preprocessor directives to check whether a symbol has been defined (#ifdef) or whether it has not been defined (#ifndef). Many programmers like to ensure that their own version of NULL is defined, not someone else's. This task can be accomplished as shown here:

#ifdef NULL
#undef NULL
#define NULL (void*) 0

The first line, #ifdef NULL, checks to see whether the NULL symbol has been defined. If so, it is undefined using #undef NULL and the new definition of NULL is defined.

To check whether a symbol has not been defined yet, you would use the #ifndef preprocessor directive.


© 2017