Re: Help wanted on some source codes
- From: "slebetman@xxxxxxxxx" <slebetman@xxxxxxxxx>
- Date: 29 Nov 2005 20:44:39 -0800
Richard Heathfield wrote:
> 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).
>
Ah yes, quite right. Extern merely means "it's somewhere else" not
"please export this". Thank you for reminding me.
.
- Follow-Ups:
- Re: Help wanted on some source codes
- From: Becker
- 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
- Re: Help wanted on some source codes
- From: Richard Heathfield
- Help wanted on some source codes
- Prev by Date: Re: sort an array of strings
- Next by Date: Re: Help wanted on some source codes
- Previous by thread: Re: Help wanted on some source codes
- Next by thread: Re: Help wanted on some source codes
- Index(es):
Relevant Pages
|