🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #931

Re: Is this a compiler bug?

#931
From: Lawrence Kirby
Date: Sat, 02 Mar 1996 23:45
45 lines
2352 bytes
In article <4h991r$qon@segfault.monkeys.com>
           rfg@monkeys.com "Ronald F. Guilmette" writes:

>I believe that in this case, the proper ANSI required behavior would be to
>print:
>
>        foo = ''
>
>because there is some special clause in the C standard about tenative
>declarations (e.g. your first declaration of the `foo' array) and their
>handling at the end of a translation unit (i.e. `static_bug.c') in cases
>where no non-tenative declaration/definition has been provided... and that
>rule says that the compiler must act as if the data object in question
>has an initializer of zero.  Thus, I believe that the compiler should
>simulate the following definition at the end of the translation unit
>unit `static_bug.c':
>
>        static const char foo[] = { 0 };

Except that 6.7.2 says:

"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"

Interestingly this is not a constraint so the compiler is not required
to issue a diagnostic.

static const char foo[];

is a tentative definition with internal linkage and an incomplete type. So
this results in undefined behaviour unless the type was completed by
composition with an *earlier* declaration. The TC1 version of 6.1.2.6 is
relevant:

  "For an identifier with internal or external linkage declared in a
   scope in which a prior declaration of that identifier is visible, if
   the prior declaration specifies internal or external linkage, the
   type of the identifier at the latter declaration becomes the
   composite type."

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID: <825810309snz@genesis.demon.co.uk>
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.uk
References: <3135FEDB.65AA@carbon.chem.nyu.edu> <4h991r$qon@segfault.monkeys.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!genesis.demon.co.uk
From: Lawrence Kirby <fred@genesis.demon.co.uk>
Newsgroups: gnu.gcc.help,comp.lang.c
Subject: Re: Is this a compiler bug?
Date: Sat, 02 Mar 96 23:45:09 GMT
Organization: none
Message-ID: <825810309snz@genesis.demon.co.uk>
References: <3135FEDB.65AA@carbon.chem.nyu.edu> <4h991r$qon@segfault.monkeys.com>
Reply-To: fred@genesis.demon.co.uk
X-NNTP-Posting-Host: genesis.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.27
X-Mail2News-Path: genesis.demon.co.uk