#undef. McGraw-Hill The Complete Reference Fourth Edition
Mainos
Mainos
246
C + + : T h e C o m p l e t e R e f e r e n c e
If macro-name has been previously defined in a #define statement, the block of code will be compiled.
The general form of #ifndef is
#ifndef macro-name
statement sequence
#endif
If macro-name is currently undefined by a #define statement, the block of code is compiled.
Both #ifdef and #ifndef may use an #else or #elif statement. For example,
#include <stdio.h>
#define TED 10 int main(void)
{
#ifdef TED printf("Hi Ted\n");
#else printf("Hi anyone\n");
#endif
#ifndef RALPH printf("RALPH not defined\n");
#endif
} return 0; will print Hi Ted and RALPH not defined. However, if TED were not defined, Hi
anyone
would be displayed, followed by RALPH not defined.
You may nest #ifdefs and #ifndefs to at least eight levels in Standard C. Standard
C++ suggests that at least 256 levels of nesting be supported.
#undef
The #undef directive removes a previously defined definition of the macro name that follows it. That is, it "undefines" a macro. The general form for #undef is
#undef macro-name
Lataa
Mainos