Re: extern "C" in library header



William Pursell <bill.pursell@xxxxxxxxx> wrote:

#ifndef FOO_HDR
#define FOO_HDR 1

#ifdef __cplusplus
extern "C" {
namespace foo {
#endif /* __cplusplus */



int foo_function(int x);



#ifdef __cplusplus
int function( int x ) { return foo_function( x ); }
} /* namespace foo */
} /* extern "C" */
#endif /* __cplusplus */
#endif /* FOO_HDR */

Bah.

The questions are:
1) Given that libfoo is a C library, and that foo.h is a
C header file, I find the above code somewhat
hideous.

That doesn't even begin to describe it.

Perhaps the best solution would be to have two headers, a foo.h for C,
and a foo.h++ for c++. A slight bit more work, but probably worth it.

Richard
.



Relevant Pages