关于c++中的预处理器指令,我有一个问题:
例如:
#ifndef QUESTION
//some code here
#ifndef QUESTION
//some code here
#endif
#endif
我们可以这样使用它吗? C++编译器能以正确的方式匹配ifndef
和endif
吗?
发布于 2011-07-13 19:54:34
是的,我们可以。#endif
语句与之前没有对应#endif
的#if
、#ifdef
或#ifndef
等相匹配。
例如:
#if ----------|
#if -----| |
#endif ---| |
#endif --------|
发布于 2011-07-13 19:55:47
可以,您可以嵌套#if
/#endif
块。一些C代码风格会告诉你要写
#ifdef CONDITION1
# ifdef CONDITION2
# endif
#endif
使用空格表示嵌套的级别。
发布于 2011-07-13 19:59:04
在您的代码中,#ifndef问题部分将被丢弃,除非您#undef问题。
祝好运!
https://stackoverflow.com/questions/6678396
复制相似问题