This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: FW: Mixing C/C++ code
- From: Tim Prince <tprince at computer dot org>
- To: Robert Wong <rgwong at cs dot ucla dot edu>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 30 Nov 2007 06:28:09 -0800
- Subject: Re: FW: Mixing C/C++ code
- References: <C375221F.1FCD%rgwong@cs.ucla.edu>
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.