Mail Archives: djgpp/1999/10/15/03:04:59
"Sunil V." wrote:
>
> Hello,
> 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 (it is basically a
> windows application).
>
> 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"
> {
>
> /* some code */
>
> }
>
> 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.
Which means if you change the file extension to .c, it would not
compile, right? That means the file is not legal C code. And your C
parser is behaving correctly when it cannot parse the post-preprocessed
(non-C) code.
> First, i want to know what does this extern "C" means?
extern "C" is a C++ construct that is used to indicate that function
prototypes following it should be considered C function, nut C++
functions, so that they don't get the standard C++ treatment (name
mangling, etc.)
> Is there any way by which i can prevent this in the preprocessed file?
Not really.
> If that is not possible, what are different ways in which this may
> appear in preprocessed code?
> (e.g. is saw some declaration like extern "C" int something; )
Either
extern "C" {
int f(int);
double g(double);
}
or
extern "C" int f(int);
You use the braces when you have more than one C functions.
--
Weiqi Gao
weiqigao AT a DOT crl DOT com
- Raw text -