jjc@UUNET.UU.NET (James Clark) (05/11/89)
I'm a bit confused about whether `extern "C"' is applicable to data as well as functions. I was using getopt(), so I declared `optind' as: extern "C" int optind; It turned out that this causes a definition of optind to be emitted, which seems to prevent getopt() from working. Declaring it as extern int optind: makes it work. So is `extern "C"' supposed to work with data? If so, how do you say that you want to refer to something, not define it? James Clark jjc@jclark.uucp
tiemann@YAHI.STANFORD.EDU (Michael Tiemann) (05/11/89)
Date: Thu, 11 May 89 09:44:00 BST From: James Clark <jclark!jjc@uunet.uu.net> I'm a bit confused about whether `extern "C"' is applicable to data as well as functions. I was using getopt(), so I declared `optind' as: extern "C" int optind; It turned out that this causes a definition of optind to be emitted, which seems to prevent getopt() from working. Declaring it as extern int optind: makes it work. So is `extern "C"' supposed to work with data? If so, how do you say that you want to refer to something, not define it? This will work: extern "C" extern int optind; James Clark jjc@jclark.uucp In the absence of more information, I think of extern "C" as being a wrapper for C code, and not to mean that everything inside is automatically to be declared extern. This is easily enough implemented, but I am not sure that is the right idea. Michael
ekrell@ulysses.att.com (06/04/89)
extern "C" {
...
}
is a wrapper for everything inside the braces, but
extern "C" int foo;
works for a single declaration. cfront 2.0 generates
extern int foo;
from that. g++ should do the same.