简体   繁体   English

#IF预处理器指令可以嵌套在ZF6F87C9FDCF8B3C3C3F07F93F1EE8712C9Z中吗?

[英]Can #if pre-processor directives be nested in C++?

I have a question about Pre-processor directives in c++:我有一个有关Z6CE809ECF90BA125B40FA4BD903962EZ的预处理前指令的疑问:

For example:例如:

#ifndef QUESTION

//some code here

#ifndef QUESTION

//some code here

#endif

#endif

Can we use it in this way, and can the C++ compiler match the ifndef and endif in the right way?我们可以以这种方式使用endif ifndef

Yes, we can.我们可以。 The #endif statement matches to the previous #if #ifdef or #ifndef etc for which there hasn't been a corresponding #endif . #endif语句与之前没有对应的#endif#if #ifdef#ifndef等相匹配。

eg例如

#if  ----------|
#if  -----|    |
#endif ---|    |
#endif --------|

Yes, you can nest #if / #endif blocks.是的,您可以嵌套#if / #endif块。 Some C coding styles would tell you to write一些 C 编码 styles 会告诉你写

#ifdef CONDITION1
# ifdef CONDITION2
# endif
#endif

using spaces to denote the level of nesting.使用空格来表示嵌套级别。

In your code, the #ifndef QUESTION section will be discarded unless you #undef QUESTION.在您的代码中,#ifndef QUESTION 部分将被丢弃,除非您使用#undef QUESTION。

Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM