C++ 如果编译器是 MSVC,是否有预处理器定义?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5850358/
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
Is there a preprocessor define that is defined if the compiler is MSVC?
提问by Avery3R
So I can do something like
所以我可以做类似的事情
#ifdef MSVC
//do compiler specific code here
#endif
回答by Alexey Kukanov
It's _MSC_VER. More info at MSDNand at predef.
它是_MSC_VER。MSDN和predef 上的更多信息。
But, be aware that some other compilers may also define it, e.g. Intel's C++ Compiler for Windows also defines _MSC_VER. If this is a concern, use #if _MSC_VER && !__INTEL_COMPILER
.
但是,请注意一些其他编译器也可能定义它,例如 Intel 的 C++ Compiler for Windows 也定义了 _MSC_VER。如果这是一个问题,请使用#if _MSC_VER && !__INTEL_COMPILER
.
回答by Mat
Look at the list of MSVC predefined macros. You'll find what you need.
查看MSVC 预定义宏列表。你会找到你需要的。
_MSC_VER
is probably a good one.
_MSC_VER
可能是一个很好的。
回答by mbx
_MSC_VER
should fit your needs
_MSC_VER
应该适合您的需求
回答by Will A
_MSC_VER is one such predefined macro.
_MSC_VER 就是这样一种预定义的宏。