#define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");
在这其中的作用是什么#ifdef
and #ifndef
,输出是什么?
里面的文字ifdef/endif
or ifndef/endif
pair将根据情况被预处理器保留或删除。ifdef
表示“如果定义了以下内容”,而ifndef
意思是“如果以下是not定义”。
So:
#define one 0
#ifdef one
printf("one is defined ");
#endif
#ifndef one
printf("one is not defined ");
#endif
相当于:
printf("one is defined ");
since one
被定义为ifdef
是真的,并且ifndef
是假的。它的定义是什么并不重要as。一段类似的(我认为更好)代码是:
#define one 0
#ifdef one
printf("one is defined ");
#else
printf("one is not defined ");
#endif
因为这在这种特定情况下更清楚地说明了意图。
在您的特定情况下,后面的文本ifdef
没有被删除,因为one
被定义为。后面的文字是ifndef
is出于同样的原因被删除。需要有两次关闭endif
行在某个点上,第一个行将导致行再次开始被包含,如下所示:
#define one 0
+--- #ifdef one
| printf("one is defined "); // Everything in here is included.
| +- #ifndef one
| | printf("one is not defined "); // Everything in here is excluded.
| | :
| +- #endif
| : // Everything in here is included again.
+--- #endif
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)