jww
jww

Reputation: 102346

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.

Upvotes: 0

Views: 330

Answers (2)

Casey
Casey

Reputation: 42574

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.

Upvotes: 7

rabensky
rabensky

Reputation: 2934

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

Upvotes: 2

Related Questions