C++ 警告:#endif 指令末尾的额外标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7467931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
warning: extra tokens at end of #endif directive
提问by venkysmarty
I am compiling a quite a big project using VxWorks6.8 C++ compiler. I am getting following warning
我正在使用 VxWorks6.8 C++ 编译器编译一个相当大的项目。我收到以下警告
warning: extra tokens at end of #endif directive
警告:#endif 指令末尾的额外标记
#ifndef _OM_NO_IOSTREAM
#ifdef WIN32
#ifndef USE_IOSTREAM
#define USE_IOSTREAM
#endif USE_IOSTREAM
#endif WIN32
I am getting a quite a lot of these warnings.
我收到了很多这样的警告。
- Why i am getting these warnings and from C++ standard point of view?
- What is the good reason why compiler is warning for this?
- What is the best way to fix this?
- 为什么我从 C++ 标准的角度收到这些警告?
- 编译器为此发出警告的充分理由是什么?
- 解决此问题的最佳方法是什么?
Thanks
谢谢
回答by Andriy Tylychko
should be:
应该:
#endif // USE_IOSTREAM
#endif // WIN32
endif
doesn't take any arguments. Such comments are placed only for readability
endif
不接受任何论据。放置此类注释只是为了便于阅读
EDIT:
编辑:
and you miss closing #endif // _OM_NO_IOSTREAM
at the end
和你错过关闭#endif // _OM_NO_IOSTREAM
末
回答by Luchian Grigore
Because you can't have anything after #endif
因为之后你什么也得不到 #endif
Also, you're missing an endif.
另外,您缺少一个endif。
#ifndef _OM_NO_IOSTREAM
#ifdef WIN32
#ifndef USE_IOSTREAM
#define USE_IOSTREAM
#endif
#endif
#endif
回答by Mahesh
#endif USE_IOSTREAM
#endif WIN32
// ^^^^^^^^^^^^ Compiler is warning about these extra tokens after endif directive.
There is no need of any identifier after #endif
. The way to suppress those warnings is to remove them.
之后不需要任何标识符#endif
。抑制这些警告的方法是删除它们。
回答by RvdK
Normally you don't put text behind the #endif. (And you are missing an #endif for OM_NO_IOSTREAM)
通常您不会在#endif 后面放置文本。(并且您缺少 OM_NO_IOSTREAM 的 #endif)
http://msdn.microsoft.com/en-us/library/ew2hz0yd%28v=vs.80%29.aspx
http://msdn.microsoft.com/en-us/library/ew2hz0yd%28v=vs.80%29.aspx