"cppaddict" <he***@hello.com> wrote in message
news:a3********************************@4ax.com...
Hi,
I want to write a C++ program, but still have access to some C code
which has a bunch of utility functions I'd like to use.
My question is: Compiling with gcc, how difficult will this be? What
do I have to do to make it work?
Thanks for any comments or references,
cppaddict
You need to make sure that your C functions have C linkage. This is
something C++ understands but C doesn't, so you need to code your headers
something like this
#ifdef __cplusplus
extern "C" { // C linkage
#endif
void some_library_function(void);
int another_library_function(int, int);
#ifdef __cplusplus
} // end C linkage
#endif
The name __cplusplus will be defined when you are using a C++ compiler but
not when you are using a C compiler.
Also note use of '(void)'. C understands () as a function with a variable
number of parameters, whereas C++ understands that as a function with zero
parameters, so use (void) which both understand.
john