#ifndef Directive

This page was translated by a robot.

The directive initiates a conditional compilation #ifndefin the same way as the #ifdirective . However, the preprocessor checks here whether the specified macro does not exist.






No Big number defined.
#include <stdio.h>
// #define THE_BIG_NUMBER 99999999

int main(){
  #ifndef THE_BIG_NUMBER
    printf("No Big number defined.\n");
  #else
    printf("Big number: %d\n", THE_BIG_NUMBER);
  #endif
  return 0;
}

Details

The #ifndefdirective does the same thing as #if ! defined.

The #ifndefdirective does not evaluate the expression to be checked, only checks its existence. If the specified macro does not exist, the condition is met and the code within the block is compiled. Otherwise it is completely discarded.

The directive is often encountered #ifndefin connection with the one-off inclusion of files , as well as when checking for debug or release .

Another common use of the #ifndefdirective is to differentiate between debug and release using the predefined macroNDEBUG