[ACCEPTED]-How to check (via the preprocessor) if a C source file is being compiled as C++ code-c-preprocessor
Accepted answer
#ifndef __cplusplus
If I remember correctly.
0
The identifier is __cplusplus
#ifdef __cplusplus
#error NO C++ PLEASE
#endif
0
#ifdef __cplusplus
with a few really ancient compilers (early 2 versions of cfront and a couple of ports) it 1 was c_pluplus
, IIRC.
#ifdef __cplusplus
0
#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.
The identifier you are looking for is __cplusplus
, which 1 can be used like this:
#ifdef __cplusplus
// Code being compiled as C++.
#endif
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.