Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 是否可以将预处理器指令嵌套在C+中+;?_C++_C Preprocessor_Preprocessor Directive - Fatal编程技术网

C++ 是否可以将预处理器指令嵌套在C+中+;?

C++ 是否可以将预处理器指令嵌套在C+中+;?,c++,c-preprocessor,preprocessor-directive,C++,C Preprocessor,Preprocessor Directive,我对c++中的预处理器指令有一个问题: 例如: #ifndef QUESTION //some code here #ifndef QUESTION //some code here #endif #endif 我们可以这样使用,C++编译器能正确地匹配 IFNDEF 和 Endif吗? < P>是的,我们可以。#endif语句与前面的#if\ifdef或#ifndef等语句匹配,但没有相应的#endif语句 e、 g 是的,您可以嵌套#if/#endif块。一些C代码风格会告诉你如

我对c++中的预处理器指令有一个问题:

例如:

#ifndef QUESTION

//some code here

#ifndef QUESTION

//some code here

#endif

#endif

我们可以这样使用,C++编译器能正确地匹配<代码> IFNDEF 和<代码> Endif吗?

< P>是的,我们可以。
#endif
语句与前面的
#if
\ifdef
#ifndef
等语句匹配,但没有相应的
#endif
语句

e、 g

是的,您可以嵌套
#if
/
#endif
块。一些C代码风格会告诉你如何编写

#ifdef CONDITION1
# ifdef CONDITION2
# endif
#endif
使用空格表示嵌套级别。

在代码中,除非您取消定义问题,否则#ifndef问题部分将被丢弃


祝你好运

我们这里有两个#endif,因此第一个#endif将与第二个#ifndef匹配?它将与前一个不匹配;这意味着我们不能嵌套它们。+1对于嵌套位,有时会对清晰度有很大帮助。为什么要插入空间?为什么不缩进
#ifdef
呢?我甚至不知道
#
和预处理器指令之间允许有空格。非常感谢你的建议!对不起,误读了代码示例!我想它是从你的IFIFF问题开始的,你可以嵌套条件句,你可以从另一个调用宏,但是不能直接嵌套宏,比如“代码> >定义AAA定义X X< /COD>,它不能正常工作。因为刚被关闭为这个副本,我会指出C和C++预处理器的规则是一样的,至少就这个问题而言。
#ifdef CONDITION1
# ifdef CONDITION2
# endif
#endif