Mail Archives: djgpp/1999/10/15/09:59:56
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2448.0">
<TITLE>RE: extern "C"</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2 FACE="Arial">> I have written a C code parser. I have to parse a test code, whose</FONT>
<BR><FONT SIZE=2 FACE="Arial">>files are with .cpp extension, but the code is in C </FONT>
<BR><FONT SIZE=2 FACE="Arial">Unlikely... .cpp is the most common C++ extension around, and it can</FONT>
<BR><FONT SIZE=2 FACE="Arial">look an awful lot like C to the un-initiated. (Besides, why would anyone </FONT>
<BR><FONT SIZE=2 FACE="Arial">save C files under C++ extensions? Many compilers, gcc in particular,</FONT>
<BR><FONT SIZE=2 FACE="Arial">use the file extension to determine the language the file is written in.)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">> I'm using gcc to preprocess the input and then parsing the</FONT>
<BR><FONT SIZE=2 FACE="Arial">>preprocessed code. Now the problem is , i have syntax error since, the</FONT>
<BR><FONT SIZE=2 FACE="Arial">>preprocessed code has something like</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">>extern "C"</FONT>
<BR><FONT SIZE=2 FACE="Arial">>{</FONT>
<BR><FONT SIZE=2 FACE="Arial">This means, compile these functions, and/or data without name mangling</FONT>
<BR><FONT SIZE=2 FACE="Arial">so I can link them to C compiled modules. (or that they are prototypes for </FONT>
<BR><FONT SIZE=2 FACE="Arial">C compiled funcs, so they won't have mangled names)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">In other words, this is a compatibility layer between C and C++.</FONT>
<BR><FONT SIZE=2 FACE="Arial">(Note that extern "C" is specific to the C++ language, so once again, this</FONT>
<BR><FONT SIZE=2 FACE="Arial">is *NOT* a C source file we are talking about here)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">>My parser cannot parse the above code. Now i cannot change extension to</FONT>
<BR><FONT SIZE=2 FACE="Arial">>.c since the code uses some header files for which _cplusplus has to be</FONT>
<BR><FONT SIZE=2 FACE="Arial">>defined.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">if _cplusplus *has* to be defined for the headers to work, then it is most certainly</FONT>
<BR><FONT SIZE=2 FACE="Arial">not a C source file. Period.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">>Is there any way by which i can prevent this in the preprocessed file?</FONT>
<BR><FONT SIZE=2 FACE="Arial">Why would you? This is a C++ source file, not C.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">>If that is not possible, what are different ways in which this may</FONT>
<BR><FONT SIZE=2 FACE="Arial">>appear in preprocessed code?</FONT>
<BR><FONT SIZE=2 FACE="Arial">extern "C" is a compiler directive, not a pre-processing directive, so it will remain</FONT>
<BR><FONT SIZE=2 FACE="Arial">as you see it after pre-processing.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Get yourself an actual C source file, and try testing it again.</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Good luck.</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01BF1711.C1DB13CA--
- Raw text -