Topic: extern "C" declarations should use C++ syn


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/07/20
Raw View
In article fnv@highway.LeidenUniv.nl, vosse@ruls41.LeidenUniv.nl (Theo Vosse) writes:
>Hi,
>
>I'm having some problems with my compiler (CodeWarrior/6 for
>the Macintosh). If I write in a C++ source file
>
>extern "C"
>{
>#include "somefile.h"
>}
>
>and write in "somefile.h" this:
>
>typedef struct X *X;
>
>the compiler says that the identifier X has already been
>declared, and that this construct is illegal.

The 'extern "C"' syntax only specifies C language linkage, as you could read
in the ARM or C++PL2. It does not mean that the code inside is interpreted
as C code; it is still C++ code. Example:
 #include <iostream.h>
 extern "C" {
  void f(); // f has no arguments, not unspecified arguments
  void g(const char* s) { cout << s; } // OK
 }
Function g can be called from C code. It is still a C++ function.

---
Steve Clamage, stephen.clamage@eng.sun.com