Skip to main content

#undef

Removes the definition for an already-defined macro.

Description

This macro preprocessor directive removes the definition for an already-defined macro. It has the form:

#undef macro-name

where macro-name is a macro that has already been defined.

#undef follows an invocation of #define or #def1arg. It works in conjunction with #ifDef and its associated preprocessor directives (#else, #endif, and #ifNDef).

The following example demonstrates code that is conditional on a macro being defined and then undefined.

#define TheSpecialPart
  
#ifDef TheSpecialPart
  WRITE "We're in the special part of the program.",!
#endif

 //
 // code here...
 //

#undef TheSpecialPart
 
#ifDef TheSpecialPart
  WRITE "We're in the special part of the program.",!
#else
  WRITE "We're no longer in the special part of the program.",!
#endif
 
#ifNDef TheSpecialPart
  WRITE "We're still outside the special part of the program.",!
#else
  WRITE "We're back inside the special part of the program.",!
#endif

where the .int code for this is:

  WRITE "We're in the special part of the program.",!
  //
  // code here...
  //
  WRITE "We're no longer in the special part of the program.",!
  WRITE "We're still outside the special part of the program.",!
FeedbackOpens in a new tab