delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/15/03:04:59

From: Weiqi Gao <weiqigao AT a DOT crl DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: extern "C"
Date: Fri, 15 Oct 1999 01:19:22 -0500
Organization: CRL Network Services
Lines: 58
Message-ID: <3806C76A.E80DBB24@a.crl.com>
References: <380574DF DOT CB287795 AT accord-soft DOT com>
NNTP-Posting-Host: a116020.stl1.as.crl.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.5-15 i586)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019