Topic: extern "C" declarations should use C++ syntax???
Author: jsa@edg.com (J. Stephen Adamczyk)
Date: 1995/07/20 Raw View
In article <3ulsif$fnv@highway.LeidenUniv.nl> vosse@ruls41.LeidenUniv.nl (Theo Vosse) writes:
>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.
>
>Is this correct?
The construct is not valid. Let's consider
typedef struct X *X;
by itself without the extern "C" wrapper. In C++, you're allowed to have
a tag name (class, struct, union, or enum) and a non-type name coexisting
in a single scope under the C compatibility "struct hack." You're also
allowed to declare a typedef name that matches the struct/union/class
defined:
typedef struct X { ... } X;
However, the case you write is neither of those. It's valid in C, but
not in C++. Putting extern "C" around it doesn't make it any more valid
in C++; as you say, the effect of extern "C" is only on linkage. It
doesn't say that what's inside is C code.
Steve Adamczyk
Author: vosse@ruls41.LeidenUniv.nl (Theo Vosse)
Date: 1995/07/20 Raw View
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.
Is this correct? According to a support engineer at MetroWerks
(the manufacturer):
The string-literal indicates the required linkage. The meaning of the
string-literal is implementation-defined. Every implementation shall
provide for linkage to functions written in the C programming language,
"C", and linkage to C++ functions, "C++". Default linkage is "C++"....
All references in the draft to 'extern "C"' involve linkage only, and not
general syntax. The ARM takes a similar stance.
Can anyone confirm this? Do I have to rewrite my code?
Thanks in advance...
--
Theo Vosse
----------
Unit for Experimental Psychology
University of Leiden
The Netherlands