Re: Help wanted on some source codes
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Wed, 30 Nov 2005 04:21:54 +0000 (UTC)
slebetman@xxxxxxxxx said:
> But I didn't think all globals are external
> linkage by default. I thought you need to use the 'extern' keyword for
> that.
No. When you do this:
extern int foo;
you are saying "dear compiler, I promise to you that there is an object
called foo, which is an int, but its storage is already reserved elsewhere
so you don't need to reserve any; just trust me on this". Each translation
unit needing to read or write foo (EXCEPT ONE) will need to have such a
line. Typically, such lines are put into a header.
In exactly one place in your program (at file scope), you must keep your
promise:
int foo;
The translation unit that has this line need not have an extern int foo; as
well (although it will do no harm if it does).
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.
- Follow-Ups:
- Re: Help wanted on some source codes
- From: slebetman@xxxxxxxxx
- Re: Help wanted on some source codes
- References:
- Help wanted on some source codes
- From: Becker
- Re: Help wanted on some source codes
- From: Old Wolf
- Re: Help wanted on some source codes
- From: slebetman@xxxxxxxxx
- Re: Help wanted on some source codes
- From: Jack Klein
- Re: Help wanted on some source codes
- From: slebetman@xxxxxxxxx
- Help wanted on some source codes
- Prev by Date: Re: Help wanted on some source codes
- Next by Date: Re: sort an array of strings
- Previous by thread: Re: Help wanted on some source codes
- Next by thread: Re: Help wanted on some source codes
- Index(es):
Relevant Pages
|