On Thu, Apr 30, 2009 at 11:57 AM, Ian Lance Taylor <i...@google.com> wrote:
> Eus <reply.to.eus.at.member.fsf....@gmail.com> writes:
>
>> 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?
>
> What you are describing is a common and traditional implementation of C,
> but it is not strictly standard conformant.  The ISO C standard says
> that "int i;" is always a definition, and "extern int i;" is always a
> declaration.  What you decribe is listed as a common extension (at least
> in C90--I didn't bother to check C99).

[I imagine Ian is aware of this anywyay, but to try to clarify...]

At file scope, "int i;" with no initializer is a "tentative
definition" in C, see 6.9.2/2; a tentative definition is an odd beast
that works in some ways rather unlike other definitions (e.g., it's
perfectly valid to have multiple tentative definitions for the same
variable in the same file).  Informally (only) it seems fair to say
that a tentative definition is "treated as a declaration only".  If
you want precision though, such fudging isn't helpful.

C++ does not have the concept of a tentative declaration:
  int i;
  int i;  // legal in C99, invalid as a duplicate definition in C++03

To me that's amusing when compared to:
  typedef int j;
  typedef int j; // legal in C++03, invalid as a duplication definition in C99

-- James

Reply via email to