Message-ID: From: George Kinney To: "'djgpp AT delorie DOT com'" Subject: RE: extern "C" Date: Fri, 15 Oct 1999 09:32:38 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01BF1711.C1DB13CA" Reply-To: djgpp AT delorie DOT com This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01BF1711.C1DB13CA Content-Type: text/plain > I have written a C code parser. I have to parse a test code, whose >files are with .cpp extension, but the code is in C Unlikely... .cpp is the most common C++ extension around, and it can look an awful lot like C to the un-initiated. (Besides, why would anyone save C files under C++ extensions? Many compilers, gcc in particular, use the file extension to determine the language the file is written in.) > I'm using gcc to preprocess the input and then parsing the >preprocessed code. Now the problem is , i have syntax error since, the >preprocessed code has something like >extern "C" >{ This means, compile these functions, and/or data without name mangling so I can link them to C compiled modules. (or that they are prototypes for C compiled funcs, so they won't have mangled names) In other words, this is a compatibility layer between C and C++. (Note that extern "C" is specific to the C++ language, so once again, this is *NOT* a C source file we are talking about here) >My parser cannot parse the above code. Now i cannot change extension to >.c since the code uses some header files for which _cplusplus has to be >defined. if _cplusplus *has* to be defined for the headers to work, then it is most certainly not a C source file. Period. >Is there any way by which i can prevent this in the preprocessed file? Why would you? This is a C++ source file, not C. >If that is not possible, what are different ways in which this may >appear in preprocessed code? extern "C" is a compiler directive, not a pre-processing directive, so it will remain as you see it after pre-processing. Get yourself an actual C source file, and try testing it again. Good luck. ------_=_NextPart_001_01BF1711.C1DB13CA Content-Type: text/html RE: extern "C"

>    I have written a C code parser. I have to parse a test code, whose
>files are with .cpp extension, but the code is in C
Unlikely... .cpp is the most common C++ extension around, and it can
look an awful lot like C to the un-initiated. (Besides, why would anyone
save C files under C++ extensions? Many compilers, gcc in particular,
use the file extension to determine the language the file is written in.)

>    I'm using gcc to preprocess the input and then parsing the
>preprocessed code. Now the problem is , i have syntax error since, the
>preprocessed code has something like

>extern "C"
>{
This means, compile these functions, and/or data without name mangling
so I can link them to C compiled modules. (or that they are prototypes for
C compiled funcs, so they won't have mangled names)

In other words, this is a compatibility layer between C and C++.
(Note that extern "C" is specific to the C++ language, so once again, this
is *NOT* a C source file we are talking about here)

>My parser cannot parse the above code. Now i cannot change extension to
>.c since the code uses some header files for which _cplusplus has to be
>defined.

if _cplusplus *has* to be defined for the headers to work, then it is most certainly
not a C source file. Period.

>Is there any way by which i can prevent this in the preprocessed file?
Why would you? This is a C++ source file, not C.

>If that is not possible, what are different ways in which this may
>appear in preprocessed code?
extern "C" is a compiler directive, not a pre-processing directive, so it will remain
as you see it after pre-processing.

Get yourself an actual C source file, and try testing it again.

Good luck.

------_=_NextPart_001_01BF1711.C1DB13CA--