Difference between preprocessor directives #if and #ifdef

守給你的承諾、 提交于 2019-12-02 16:29:47

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

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