FW: Mixing C/C++ code

Tim Prince tprince@computer.org
Fri Nov 30 16:05:00 GMT 2007


Robert Wong wrote:

> Also, I'm a bit unclear on how the: extern "C" / extern "C++" notation
> works. If I am using g++ to compile both my C and C++ code...when and which
> of these should I use? Also, I read somewhere that I shouldn't use these
> externs if I'm on a solaris machine, is that right?

extern "C" defines a function with C linkage, so it is visible across
languages.  It's the standard way to do that.  If you are using gcc/g++
on Solaris, as far as I know it should work the same as on any other OS.
It's conceivable that Solaris linker knows things which would permit
inter-language linking without extern "C."  Unless you find an expert on
inter-Solaris compatibility (given there are several incompatible
Solaris architectures), if this is not a crucial subject of your
project, you should avoid it.
C++ linkage supports over-loaded functions, C linkage doesn't.



More information about the Gcc-help mailing list