This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/15360] c99: extern w/initializer; extern w/internal linkage


------- Additional Comments From hozelda at yahoo dot com  2004-07-07 08:43 -------
Let me clarify some things, and let me also summarize right now that I *do* still 
think something is wrong with gcc. 
 
 
static int z; static int z = 5; extern int z; static int z; 
 
is compiled without warnings. This means that I was probably wrong to say that 
gcc doesn't recognize extern redeclarations of "internal variables." I say 
"probably" because I don't know that gcc isn't changing the linkage back and 
forth for the above, so that after the 'extern int z' it would stand at external 
linkage, and then revert back to internal after the last static declaration. 
 
I don't know that because I haven't tested the runtime and linkage behavior and I 
am not very familiar with the gcc code base; however, I am probably wrong 
given that gcc didn't produce errors or warnings when I compiled this last 4 
statements along with an otherwise correct program. 
 
The reason I was mistaken was because, in the error mentioned originally, there 
was more than one error comment, the second of which seemed to indicate that 
gcc probably was not considering that extern could refer to internal 
objects/identifiers. Anyway, all bets are off during error "recovery," and I should 
have tried to isolate each of the supposed 2 separate errors before posting. 
 
 
What is probably happening is that gcc is not allowing 'extern int z =....' And 
this is the only error apparently. 
 
 
Currently, I am not familiar with gcc internals very much, but most reading this 
probably are or have some descent idea of what is going on. I am also not 
following any mailing list discussions, so when people post with very brief 
statements, I really have no idea about what is going on. 
 
 
In any case, gcc fails to compile properly code straight from section 6.9.2 
(example 4 w/ modifications). I don't see that there is anything wrong with the 
examples even if my original assessment of what was wrong with gcc was 
inaccurate. 
 
 
So, to recap, 
 
extern int x = 8;  //only declaration of x at file scope or within the final program; 
 
should be accepted by gcc, and if we want to believe the compilation results of 
the programs above, gcc is failing to accept it. 
 
..though if it shouldn't accept it, why not? [please be specific because I copied 
code straight from 6.9.2#4 and gcc would not compile it completely or link it 
afterwards or something. ..And please, *reopen* the bug if the person that 
closed it or someone else can't answer this.] 
 
 
 
 
Part II 
 
A further test: 
 
 
static int z1; 
static int z1; 
static int z1; 
extern int z1; 
static int z1; 
static int z1; 
static int z1; 
 
 
produces no errors or warnings, but: 
 
 
static int z1; //line 489 
static int z1; 
static int z1; 
extern int z1=8; //line 492 
static int z1; 
static int z1; 
static int z1; //line 495 
 
 
leads to: 
 
 
practice.c: At top level: 
practice.c:492: warning: `z1' initialized and declared `extern' 
practice.c:492: conflicting declarations of `z1' 
practice.c:491: `z1' previously declared here 
practice.c:493: conflicting declarations of `z1' 
practice.c:492: `z1' previously defined here 
 
 
I think this is what tripped me up. [And feel free to interpret it differently.] At least 
during error recovery, it seems that gcc displays some of the behavior I 
incorrectly attributed to it originally.. that it always interprets extern to mean 
external declarations. ..Maybe not always but only when there is an initializer 
together with the extern declaration. 
 
 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15360


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]