user6795571 user6795571 - 2 months ago 12
C Question

universal preprocessor define for C or C++?

my code can be compiled with C or C++ compilers.
I'd like to know which one is doing the compilation

is there preprocessor define to tell me this ?

Answer

The definition is __cplusplus.

#ifdef __cplusplus 
// treated as C++ code
#else
// treated as C code
#endif // __cplusplus