This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/15360] c99: extern w/initializer; extern w/internal linkage
- From: "hozelda at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 May 2004 16:16:53 -0000
- Subject: [Bug c/15360] c99: extern w/initializer; extern w/internal linkage
- References: <20040510002635.15360.hozelda@yahoo.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From hozelda at yahoo dot com 2004-05-10 16:16 -------
(In reply to comment #0)
...
> program a.in.c:
>
> static int x0;
> extern int x0=8;
> int main() {
> }
>
> [[[ gcc -std=c99 -o a.out a.in.c ]]]
> produces error:
>
> a.in.c:2: warning: `x0' initialized and declared `extern'
> a.in.c:2: conflicting declarations of `x0'
> a.in.c:1: `x0' previously declared here
>
...
> Also looking back at the 3 messages that gcc produced to the example at the
> top, it seems to me that, in addition to disliking extern with initialization, gcc
> doesn't believe that extern can be used with an identifier that already has
> internal linkage.
>
> So, gcc doesn't believe...
> -- extern can be used with an initialization [at file scope!]
> -- extern can be used to redeclare an identifier with prior internal linkage.
>
> Clearly, if the draft standard is correct, something is wrong when gcc produces
> warnings to the very example that the document says is acceptable. This is for
> the case of extern with initialization at file scope.
...
Update:
I modified the little test program. Also, I now think that gcc's behavior may not be that bad
for the warning given: warning: >> `x0' initialized and declared `extern' .
I think gcc produces at least to types of warnings. Those where the program portion is
correct but is perhaps unrecommended usage/style or where it is likely that the programmer
intended for something else (i.e. a "be careful" warning). The other type is where the
program violates part of the standard (for -std=c99) but gcc makes assumptions, sets
defaults, or behaves in some implementation defined (consistent) fashion. This type of
warning is also ok.
An example of this latter one would be:
... int f(a) {return 0;} ...
Here we should have either 'int f(<sometype> a) {...}' or 'int f(a) <sometype> a; {..}' or
similar. In this case, gcc warns and then defaults to give 'a' the type 'int'.
Hopefully what I am saying is accurate. But there still seems to be a problem.
#include <stdio.h>
static int x0;
extern int x0=8;
int main() {
puts("hello everyone");
return 0;
}
This is supposed to be a legal program as I explained earlier (notice that this program is a
bit modified from the first one). If so, regardless of warnings or of any diagnostic, gcc has
to produce an executable that behaves properly, but gcc failed to produce any executable. [I
used the same shell command as in earlier example.]
I have not tested to see which part of the gcc program is failing, for I am assuming it is at
least the compiler portion.
Recap:
gcc may not like...
-- extern declarations that are initialized, but this may be ok.
gcc doesn't believe...
-- a program that has an extern that redeclare an identifier with prior internal linkage is a
safe part of an executable. I still think this is a mistake.
Sorry for the misunderstanding on my part with respect to the warning.. though I am now
*assuming* that gcc would have initialized the extern variable properly if it weren't for the
line2 "error" (I haven't tested this).
hozelda@..., the original poster
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15360