Does extern "C" affect compilation mode
Graham Bloice
gbloice@gmail.com
Sat Feb 19 11:48:00 GMT 2011
I'm getting problems with g++ compiling some headers:
#ifdef __cplusplus
extern "C" {
#endif
typedef enum abc xyz;
enum abc {
p1 = 0,
p2,
p3
};
#ifdef __cplusplus
}
#endif
This code compiles with the mbed cloud compiler, Keil RV and VS2010,
but not g++ 4.4.5. The errors are:
test.cpp:5: error: use of enum ‘abc’ without previous declaration
test.cpp:5: error: invalid type in declaration before ‘;’ token
From a previous query I understand that the code isn't legal c++, but
is legal c, as demonstrated when I compile the code using the -x c
option.
I'm guessing here, but do some compilers switch into a C compilation
mode when they hit an extern "C"? I know extern "C" affects the
linkage but is it meant to affect compilation mode?
--
Regards,
Graham Bloice
More information about the Gcc-help
mailing list