🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1980

extern "C" int optind;

#1980
From: Michael Tiemann
Date: Thu, 11 May 1989 12:38
33 lines
1419 bytes
   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
Technical Details
Message-ID: <8905111238.AA01096@yahi.stanford.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!YAHI.STANFORD.EDU!tiemann
References: <8905110844.AA24762@jclark.uucp>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!YAHI.STANFORD.EDU!tiemann
From: tiemann@YAHI.STANFORD.EDU (Michael Tiemann)
Newsgroups: gnu.g++.bug
Subject: extern "C" int optind;
Message-ID: <8905111238.AA01096@yahi.stanford.edu>
Date: 11 May 89 12:38:07 GMT
References: <8905110844.AA24762@jclark.uucp>
Sender: daemon@tut.cis.ohio-state.edu
Reply-To: tiemann@lurch.stanford.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 33