C++ Usage Issues - Problems, Solutions, and Suggestions

Hoan Hoang hoan at tidalstream.com
Fri Jun 22 11:15:00 UTC 2007

I think the standard way for C prototypes to compile both in C or C++
would be as bellow because C compiler would not understand extern "C".

#ifdef __cplusplus
extern "C" {

/* Prototypes here */

#ifdef __cplusplus

__cplusplus is a standard macro defined in all C++ compiler so you don't
need to worry about defining macroes when porting to other platforms.

> 2. Some header files are not quite ready for C++ compatibility. 
> Specifically, this exercise found one, rtems/rtems_bsdnet.h, that does
> not include appropriate measures.  Having to type this:
>     extern "C" {
>     #include <rtems/rtems_bsdnet.h>
>     }
> is ugly and just plain wrong.  This header, and others like it, should
> be modified to use the _BEGIN_STD_C and _END_STD_C appropriately to
> encapsulate definitions that the C++ compiler will otherwise mangle. 
> Using these macros are better then simply extern "C" { }  approach too,
> because they seem to handle the std namespace correctly.

More information about the users mailing list