tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] defined twice error commented out


From: grischka
Subject: Re: [Tinycc-devel] defined twice error commented out
Date: Thu, 29 Oct 2015 19:35:09 +0100
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

Michael Matz wrote:
... In C it's not allowed to have two definitions of the same non-static symbol, simple as that. It's not only for when initialized with different values or the like; it's undefined no matter what.

Maybe it isn't that clear.  See below from the c99 draft, in particular
the word "tentative".

Anyway, it's not that TCC's behavior in that area couldn't be better.
Whether or not -f(no-)common should make a difference may be arguable
too.

-- gr


6.9.2 External object definitions

Semantics

1 If the declaration of an identifier for an object has file scope
  and an initializer, the declaration is an external definition for
  the identifier.

2 A declaration of an identifier for an object that has file scope
  without an initializer, and without a storage-class specifier or
  with the storage-class specifier static, constitutes a tentative
  definition. If a translation unit contains one or more tentative
  definitions for an identifier, and the translation unit contains
  no external definition for that identifier, then the behavior is
  exactly as if the translation unit contains a file scope declaration
  of that identifier, with the composite type as of the end of the
  translation unit, with an initializer equal to 0.

3 If the declaration of an identifier for an object is a tentative
  definition and has internal linkage, the declared type shall not
  be an incomplete type.

4 EXAMPLE 1

int i1 = 1;         // definition, external linkage
static int i2 = 2;  // definition, internal linkage
extern int i3 = 3;  // definition, external linkage
int i4;             // tentative definition, external linkage
static int i5;      // tentative definition, internal linkage

int i1; // valid tentative definition, refers to previous
int i2; // 6.2.2 renders undefined, linkage disagreement
int i3; // valid tentative definition, refers to previous
int i4; // valid tentative definition, refers to previous
int i5; // 6.2.2 renders undefined, linkage disagreement

extern int i1; // refers to previous, whose linkage is external
extern int i2; // refers to previous, whose linkage is internal
extern int i3; // refers to previous, whose linkage is external
extern int i4; // refers to previous, whose linkage is external
extern int i5; // refers to previous, whose linkage is internal

5 EXAMPLE 2

If at the end of the translation unit containing
    int i[];
the array i still has incomplete type, the implicit initializer causes
it to have one element, which is set to zero on program startup.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]