简体   繁体   English

什么是C ++ 03宏?

[英]What are the C++ 03 Macros?

I'm trying to compile a library using -std=c++03 , but compilation is failing because nullptr_t is not defined. 我正在尝试使用-std=c++03编译库,但是编译失败,因为nullptr_t

How can I guarantee C++03 instead of C++11 compilation using a hard-coded macro? 如何使用硬编码宏保证C ++ 03而不是C ++ 11编译?

Thanks in advance. 提前致谢。

The only version detection present in the standard is the value of the macro __cplusplus : 201103 for C++11 (ISO/IEC 14882-2011 §16.8/1) and 199711 for C++98 (ISO/IEC 14882-1998 §16.8/1). 存在于标准的唯一版本检测是宏的值__cplusplus201103为C ++ 11(ISO / IEC 14882-2011§16.8/ 1)和199711对C ++ 98(ISO / IEC 14882-1998§16.8 / 1)。 C++03 didn't apparently deserve its own number and uses 199711 as well (ISO/IEC 14882-2003 §16.8/1). C ++ 03显然不值得拥有自己的编号,并且也使用199711 (ISO / IEC 14882-2003§16.8/ 1)。 If this seems inadequate to you as a means of feature detection, you're not alone . 如果您觉得这不足以进行特征检测, 那么您并不孤单

In any case, you will probably need to consult the documentation of the library in question to determine how to configure it for pre-C++11 if such is even possible. 无论如何,您甚至可能需要查阅相关库的文档,以确定如何针对C ++ 11之前的版本配置它。

Unfortunately I don't know of any macros that work for all compilers. 不幸的是,我不知道任何适用于所有编译器的宏。 For g++ and clang there is a macro named __GXX_EXPERIMENTAL_CXX0X__ that is only defined in c++11, so you can do 对于g ++和clang,有一个名为__GXX_EXPERIMENTAL_CXX0X__的宏,仅在c ++ 11中定义,因此您可以执行

#ifndef __GXX_EXPERIMENTAL_CXX0X__
  // Do some c++03 specific code
#endif

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

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