🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #930

Re: Is this a compiler bug?

#930
From: Ronald F. Guilmette
Date: Sat, 02 Mar 1996 10:48
69 lines
2549 bytes
In article <3135FEDB.65AA@carbon.chem.nyu.edu>,
Edward J. Huff <huffe@carbon.chem.nyu.edu> wrote:
>The gcc documentation states:
>> If the compiler does not produce an error message for invalid 
>> input, that is a compiler bug. However, you should note that 
>> your idea of "invalid input" might be my idea of "an extension"
>> or "support for traditional practice".
>
>Is this a bug?  Or is it "support for traditional practice"?
>
>carbon% head static*.c
>==> static_bug.c <==
>static const char foo[];
>
>int
>main(int argc, const char *argv[]) {
>  printf("foo = '%s'\n",foo);
>  return 0;
>}
>
>#ifdef DEFINE_IT
>static const char foo[] = "bar";
>#endif
>
>==> static_bug2.c <==
>const char foo[] = "baz";
>carbon% gcc static*.c
>carbon% a.out
>foo = 'baz'

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 };

>carbon% gcc -DDEFINE_IT static*.c
>carbon% a.out
>foo = 'bar'

Obviously, GCC _is_ correctly handling this case.

>The IRIX C compiler gives an error:
>
>archimedes 23% cc static*.c
>static_bug.c:
>cfe: Error: static_bug.c, line 1: storage size for 'foo' isn't known
> static const char foo[];
> ------------------^

I don't think that is valid behavior for s standard conforming compiler.
(See above.)

I suggest asking over in comp.std.c about this whole issue.
-- 

-- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
---- E-mail: rfg@monkeys.com ----------- Purveyors of Compiler Test Suites -
------ Copyright (c) 1996 by Ronald F. Guilmette; All rights reserved. -----
Technical Details
Message-ID: <4h991r$qon@segfault.monkeys.com>
Path: arc1-ca.pugleaf.net!monkeys.com!not-for-mail
References: <3135FEDB.65AA@carbon.chem.nyu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!monkeys.com!not-for-mail
From: rfg@monkeys.com (Ronald F. Guilmette)
Newsgroups: gnu.gcc.help,comp.lang.c
Subject: Re: Is this a compiler bug?
Date: 2 Mar 1996 02:48:27 -0800
Organization: Infinite Monkeys & Co.
Message-ID: <4h991r$qon@segfault.monkeys.com>
References: <3135FEDB.65AA@carbon.chem.nyu.edu>
NNTP-Posting-Host: segfault.monkeys.com