gcc defines different macors for .cxx and .cpp
Ralf Fassel
ralf@akutech.de
Thu Apr 13 10:00:00 GMT 2000
gcc 2.95.2 and 2.7.2.1 on IRIX 5
gcc 2.95.1 on IRIX 6
The manual states:
For any given input file, the file name suffix determines what kind
of compilation is done:
--<snip-snip>--
`FILE.cc'
`FILE.cxx'
`FILE.cpp'
`FILE.C'
C++ source code which must be preprocessed. Note that in `.cxx',
the last two letters must both be literally `x'. Likewise, `.C'
refers to a literal capital C.
But the predefined macros are different for .cpp and .cxx files on the
above systems if applied on an empty file:
% rm foo.cxx foo.cpp
% touch foo.cpp foo.cxx
% gcc -E -dM foo.cxx > cxx
% gcc -E -dM foo.cpp > cpp
% diff -c cxx cpp
*** cxx Thu Apr 13 18:40:02 2000
--- cpp Thu Apr 13 18:39:57 2000
***************
*** 1,9 ****
! #define _LANGUAGE_C_PLUS_PLUS 1
! #define __LANGUAGE_C_PLUS_PLUS 1
#define __host_mips 1
#define __mips64 1
#define SYSTYPE_SVR4 1
#define __MIPSEB 1
#define __DSO__ 1
#define _MIPS_SZLONG 32
#define __EXCEPTIONS 1
--- 1,9 ----
! #define __LANGUAGE_C 1
#define __host_mips 1
#define __mips64 1
#define SYSTYPE_SVR4 1
#define __MIPSEB 1
+ #define _LANGUAGE_C 1
#define __DSO__ 1
#define _MIPS_SZLONG 32
#define __EXCEPTIONS 1
***************
*** 37,42 ****
--- 37,43 ----
#define __GNUG__ 2
#define __EXTENSIONS__ 1
#define _MIPS_ISA _MIPS_ISA_MIPS3
+ #define LANGUAGE_C 1
#define __sgi__ 1
#define _COMPILER_VERSION 601
#define _MIPS_SIM _ABIN32
As you can see from the diff output, .cxx files (and .cc and .C for
that matter) #define LANGUAGE_CPLUS_PLUS (and _cplusplus, not shown in
the diff), but .cpp files #define LANGUAGE_C (*and* _cplusplus).
If one uses the -v flag to gcc, it is obvious that the difference
comes from the calling of the preprocessor:
% gcc -E -dM -v foo.cxx > /dev/null
gcc version 2.7.2.1
/software/gcc/2.7.2.1/IRIX-5/lib/gcc-lib/mips-sgi-irix5.3/2.7.2.1/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus
--<snip-snip>--
-D_LONGLONG -D_LANGUAGE_C_PLUS_PLUS -D_MIPS_FPSET=16
^^^^^^^^^^^^^^^^^^^^^^^
% gcc -E -dM -v foo.cpp > /dev/null
gcc version 2.7.2.1
/software/gcc/2.7.2.1/IRIX-5/lib/gcc-lib/mips-sgi-irix5.3/2.7.2.1/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus
--<snip-snip>--
-D_LONGLONG -D_LANGUAGE_C -DLANGUAGE_C -D_MIPS_FPSET=16
^^^^^^^^^^^^^^^^^^^^^^^^^^
Is this intentional? From the sources in gcc.c, `.cpp' and `.cxx'
both are linked to {"#C++"}, so it looks like a bug or a compilation
problem to me.
This does not happen in gcc 2.7.2.1 on SunOS 5 or HP-UX-9 (neither
*LANGUAGE* macros is deifned there).
Please CC any response to me, since I'm not on the mailing list.
Thanks for listening.
R'
More information about the Gcc-bugs
mailing list