www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/07/05:39:25

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: DJGPP is not strict enough ???
Date: Thu, 06 Feb 1997 19:46:09 -0800
Organization: Two pounds of chaos and a pinch of salt
Lines: 39
Message-ID: <32FAA581.4025@cs.com>
References: <1997Feb5 DOT 173245 DOT 93344 AT cc DOT usu DOT edu> <32F96574 DOT 2C36 AT cs DOT com> <5dcq7h$mji AT lyra DOT csx DOT cam DOT ac DOT uk>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp103.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Michael Meeks wrote:
> 
> <newbie> What about extern ?, should it be used in all .h file function
> prototypes in C ? is C++ different ?
> </newbie>

<duh> 'extern' is not a gcc command line option, so of course I didn't
mention it.  :) </duh>

<answer>
The 'extern' qualifier must be used in any variable declaration that
references a variable _defined_ in another source file.  This applies by
default to variables declared in header files, so of course you should
use it there.  You should never actually define a variable in a header
unless the header is specific to only one source file, because if the
header gets included in more than one source file, the linker will
complain about multiple definitions.

'extern' can also be used for function declarations, but it's
unnecessary because 'extern' is implicit in all function declarations
that are not declared 'static'.

I don't know offhand of any reason why C++ would be different, except
that there are probably more uses for those keywords than in C.  I'm not
exactly a C++ expert.  :)

For a complete list of the uses of 'extern' and 'static', see any good
C/C++ text.
</answer>

Hope this helps!

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
|    *  Proud user of DJGPP!  *    |   http://www.cs.com/fighteer   |
|    ObJoke:  If Bill Gates were a robber, not only would he        |
|     shoot you, but he'd send you a bill for the bullets.          |
---------------------------------------------------------------------

- Raw text -


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