简体   繁体   中英

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.

How can I guarantee C++03 instead of C++11 compilation using a hard-coded macro?

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). C++03 didn't apparently deserve its own number and uses 199711 as well (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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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