C++ Migration Guide

Creating Generic Header Files

K&R C, ANSI C, and C++ require different header files. To make C++ header files conform to K&R C and ANSI C standards so that they are generic, use the macro _ _cplusplus to separate C++ code from C code. The macro _ _STDC_ _ is defined in both ANSI C and C++. Use this macro to separate C++ or ANSI C code from K&R C code.

You can insert an #ifdef statement in your code to conditionally compile C++ or C using the C++ compiler. To do this, use the _ _cplusplus macro:


#ifdef __cplusplus 
extern "C" int myfunc(int); // C++ declaration 
#else 
int myfunc();               /* K&R C declaration */ 
#endif 


Note -

In the past, this macro was c_plusplus, which is no longer accepted.