[ACCEPTED]-How to check (via the preprocessor) if a C source file is being compiled as C++ code-c-preprocessor

Accepted answer
Score: 11
#ifndef __cplusplus

If I remember correctly.

0

Score: 5

The identifier is __cplusplus

#ifdef __cplusplus
#error NO C++ PLEASE
#endif

0

Score: 2

#ifdef __cplusplus

with a few really ancient compilers (early 2 versions of cfront and a couple of ports) it 1 was c_pluplus, IIRC.

Score: 2
#ifdef __cplusplus

0

Score: 2

#ifdef __cplusplus

I think the file extension matters too, if 3 the C++ compiler is given a .c file it will 2 compile it as C code. i have nothing to 1 back this up though.

Score: 1

The identifier you are looking for is __cplusplus, which 1 can be used like this:

#ifdef __cplusplus
// Code being compiled as C++.
#endif

More Related questions