Preprocessor directive to test if this is C or C++

Posted by Collin on Stack Overflow See other posts from Stack Overflow or by Collin
Published on 2012-09-22T23:24:41Z Indexed on 2012/09/23 3:37 UTC
Read the original article Hit count: 197

Filed under:
|
|

I'm trying to find a standard macro which will test whether a header file is being compiled as C or as C++. The purpose of this is that the header may be included by either C or C++ code, and must behave slightly differently depending on which. Specifically:

In C, I need this to be the code:

extern size_t insert (const char*);

In C++, I need this to be the code:

extern "C" size_t insert (const char*);

Additionally, is there a way to avoid putting #ifdef's around every declaration in the header?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c