我对 C++ 中的预处理器指令有疑问:
例如:
#ifndef QUESTION
//some code here
#ifndef QUESTION
//some code here
#endif
#endif
我们可以这样使用吗,C++编译器能正确匹配ifndefandendif吗?
我对 C++ 中的预处理器指令有疑问:
例如:
#ifndef QUESTION
//some code here
#ifndef QUESTION
//some code here
#endif
#endif
我们可以这样使用吗,C++编译器能正确匹配ifndefandendif吗?
我们可以。该#endif语句与#if #ifdef没有#ifndef对应的#endif.
例如
#if ----------|
#if -----| |
#endif ---| |
#endif --------|
是的,你可以嵌套#if/#endif块。一些 C 编码风格会告诉你写
#ifdef CONDITION1
# ifdef CONDITION2
# endif
#endif
使用空格来表示嵌套级别。
在您的代码中,#ifndef QUESTION 部分将被丢弃,除非您使用#undef QUESTION。
祝你好运!