tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] global variables in tcc


From: Lluís Batlle i Rossell
Subject: Re: [Tinycc-devel] global variables in tcc
Date: Tue, 2 Apr 2013 14:10:59 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Mon, Apr 01, 2013 at 10:41:44PM +0100, Rob wrote:
> On Mon, Apr 01, 2013 at 09:27:22PM +0200, Lluís Batlle i Rossell wrote:
> > On Mon, Apr 01, 2013 at 08:58:06PM +0200, Daniel Glöckner wrote:
> > > On Mon, Apr 01, 2013 at 04:55:18PM +0200, Lluís Batlle i Rossell wrote:
> > > > > GCC and Clang allow these to be merged together at link-time,
> > > > > which means users who make mistakes such as missing `extern' in
> > > > > header files still get the multiple definitions merged.
> > > > >
> > > > > tcc is stricter and perhaps more conformant in disallowing this.
> > > >
> > > > I think that the C standard requires the gcc and clang behaviour,
> > > > 'extern' never being a required word.
> > > >
> > > > No?
> > >
> > > I just took a look inside the N1570 C11 draft.
> > > Chapter 6.9 paragraph 5 says:
> > >
> > > "If an identifier declared with external linkage is used in an
> > > expression ([...]), somewhere in the entire program there shall be
> > > exactly one external definition for the identifier; otherwise, there
> > > shall be no more than one."
> >
> > From K&R:
> >
> > "An external declaration for an object is a definition if it has an
> > initializer.  An external object declaration that does not have an
> > initializer, and does not contain the extern specifier, is a tentative
> > definition. If a definition for an object appears in a translation
> > unit, any tentative definitions are treated merely as redundant
> > declarations. If no definition for the object appears in the
> > translation unit, all its tentative definitions become a single
> > definition with initializer 0."
> >
> > I don't know if this is a fight between K&R and the C11 draft. :)
> >
> > Regards,
> > Lluís.
> 
> I think that just means per translation unit, i.e.:

As I can read in C99 (6.9.2), I agree with you.

But K&R (Prentice Hall, 2nd edition) adds after the cited paragraph (A10.2):

"Each object must have exactly one definition. For objects with internal 
linkage,
this rule applies separately to each translation unit, because internally-linked
objects are unique to a translation unit. For objects with external linkage, it
*applies to the entire program*."



reply via email to

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