Difference between preprocessor directives #if and #ifdef

走远了吗. 提交于 2019-12-03 02:57:10

问题


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

#if

and

#ifdef

回答1:


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).




回答2:


#ifdef FOO

is a shortcut for:

#if defined(FOO)

#if can also be used for other tests or for more complex preprocessor conditions.

#if defined(FOO) || defined(BAR)


来源:https://stackoverflow.com/questions/3802988/difference-between-preprocessor-directives-if-and-ifdef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!