This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: (extern int vs. int) and (extern function vs. function) (was: gcc-in-cxx update)
- From: Gabriel Dos Reis <dosreis at gmail dot com>
- To: eus at member dot fsf dot org
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, Manuel López-Ibáñez <lopezibanez at gmail dot com>, Ian Lance Taylor <iant at google dot com>, gcc at gcc dot gnu dot org
- Date: Fri, 1 May 2009 01:02:07 -0500
- Subject: Re: (extern int vs. int) and (extern function vs. function) (was: gcc-in-cxx update)
- References: <m3hc0729jr.fsf@google.com> <Pine.LNX.4.64.0904291120200.23778@digraph.polyomino.org.uk> <6c33472e0904290513j44b3cafdl77b38de0cd2619cd@mail.gmail.com> <Pine.LNX.4.64.0904291321570.25453@digraph.polyomino.org.uk> <6c33472e0904290642j4b243ba3u4ec76b71b0c0e410@mail.gmail.com> <Pine.LNX.4.64.0904291456280.27093@digraph.polyomino.org.uk> <6c33472e0904290819o3b0dafd4s750be6543484dabe@mail.gmail.com> <Pine.LNX.4.64.0904291537250.27093@digraph.polyomino.org.uk> <1241092470.6783.20.camel@eus-laptop>
- Reply-to: gdr at integrable-solutions dot net
On Thu, Apr 30, 2009 at 6:54 AM, Eus
<reply.to.eus.at.member.fsf.org@gmail.com> wrote:
> Hi Ho!
>
> Sorry, if I sort of hijack this thread.
>
> On Wed, 2009-04-29 at 15:43 +0000, Joseph S. Myers wrote:
>
>> > > "int i;" is not the same as "extern int i;".
>> >
>> > Sorry for my ignorance but I have been reading and searching for the
>> > answer and I cannot tell what is the difference between "int i = 1"
>> > and "extern int i = 1" at file-scope in C.
>>
>> I did not say those were different, I said the uninitialized case was
>> different, so "extern is implicit if missing" is not a general C rule.
>
> I think the difference between "int i;" and "extern int i;" at
> file-scope in C is that "int i;" will only be treated as a definition if
> it is not defined in another place in the same file/TU. IOW, its linkage
> is internal within the TU itself. But, "extern int i" is definitely
> treated as a declaration only that can later be defined either in the
> same TU or in another one.
>
> Is that true?
Yes. C has the notion of tentative definition and C++ does not. I.e.
in C,
int i;
is a tentative definition of 'i'; in C++ it is a definition -- so
cannot be repeated.