Mail Archives: djgpp/1997/02/07/05:39:25
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 -