The #ifdef directive

The #ifdef directive checks for the existence of macro definitions.

If the identifier specified is defined as a macro, the lines of code that immediately follow the condition are passed on to the compiler.

Read syntax diagramSkip visual syntax diagram#ifdef directive syntax
 
                         .----------------.
                         V                |
>>-#--ifdef--identifier----token_sequence-+--------------------->
 
>--newline_character-------------------------------------------><
 

The following example defines MAX_LEN to be 75 if EXTENDED is defined for the preprocessor. Otherwise, MAX_LEN is defined to be 50.

#ifdef EXTENDED
#   define MAX_LEN 75
#else
#   define MAX_LEN 50
#endif


[ Top of Page | Previous Page | Next Page | Contents | Index ]