Detecting the gcc version in the source code

V

Vivek Krishna

Hi ,
I am writing code that makes use of certain C++ STL features (ex
hash_map) and their usage is slightly different between versions<3.3
and versions beyond 3.3 ,such as which file to include (ext/hash_map
or hash_map ) and whether to define the __gnu_cxx namespace. I want to
be able to detect using a macro (preferably ) which g++ version I am
using and write code for accordingly ..Is this possible.
Vivek
 
R

Rolf Magnus

Vivek said:
Hi ,
I am writing code that makes use of certain C++ STL features (ex
hash_map) and their usage is slightly different between versions<3.3
and versions beyond 3.3 ,such as which file to include (ext/hash_map
or hash_map ) and whether to define the __gnu_cxx namespace. I want to
be able to detect using a macro (preferably ) which g++ version I am
using and write code for accordingly ..Is this possible.
Vivek

First of all, you're off-topic in comp.lang.c++ (dunno about the other
group). This question would rather belong in gnu.g++.help. And then yes, of
course you can find out the version. On a un*x system, do:

echo | g++ -E -x c++ -dm -

and you'll see a list of all pre-defined macros. I can see things like:

#define __GNUC__ 3
#define __GNUC_MINOR__ 3
#define __GNUC_PATCHLEVEL__ 3
#define __VERSION__ "3.3.3"

in that output.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top