RE: How can I differentiate C and C++ compiler?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Dave,

Here are some defines you could test against which show up for C++ and are absent for C:

__GNUG__
__GXX_WEAK__
__cplusplus

Note that the gcc compiler can compile either C or C++ code.  And the g++ compiler can compile either C or C++ code.  (As I understand it, neither gcc or g++ is a compiler per se.  Rather, they are toolchain drivers, which invoke the compiler.)

You can also explicitly tell the toolchain driver that the code is C or C++, using -x c and -x c++ (amongst others, see 'man gcc'), and which particular standard to adhere to by -std=<standard> (see 'man gcc').

To view the predefined preprocessor defines that are provided, for example:

echo '' | g++ -std=c++98 -ansi -pedantic -E -dM -x c++ - | sort 

Change the parameters a bit as desired, and save the outputs, and diff them to see the deltas.

Sincerely,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux