Difference between preprocessor directives #if and #ifdef

前端 未结 2 533
甜味超标
甜味超标 2021-01-30 20:11

What is the difference (if any) between the two following preprocessor control statements.

#if

and

#ifdef
2条回答
  •  旧巷少年郎
    2021-01-30 20:31

    You can demonstrate the difference by doing:

    #define FOO 0
    #if FOO
      // won't compile this
    #endif
    #ifdef FOO
      // will compile this
    #endif
    

    #if checks for the value of the symbol, while #ifdef checks the existence of the symbol (regardless of its value).

提交回复
热议问题