Pelles C forum

Pelles C => Bug reports => Topic started by: dsula on April 26, 2006, 11:42:13 PM

Title: redeclaration
Post by: dsula on April 26, 2006, 11:42:13 PM
Pelle,

The compiler doesn't catch redeclaration of global vars.
e.g.

int a, a;
int main(void) {...}

It catches redeclaration of auto vars, though.

ds
Title: redeclaration
Post by: Pelle on April 27, 2006, 02:47:47 PM
Just a quick test: one Microsoft, and one GNU, compiler seems perfectly happy with this - not even a warning. I will see if the C standard says anything about it... (not sure it does).

Pelle
Title: redeclaration
Post by: frankie on April 27, 2006, 03:17:41 PM
I think it could be consistent with the sharing of global variables.
If I well remember M$ C compiler (the old DOS version at least) automatically allocate a global variable if are present one or more external declarations of the same variable (i.e. "#external int a"), also if there is no allocation (i.e. "int a") in any module.
Of course defining the same variable on the same line and in the same module seems odd, but sintactically correct for the language grammar.
Title: redeclaration
Post by: dsula on April 27, 2006, 09:26:52 PM
My old DOS Borland C v3.1 complains about it. Well anyways. I see no reason why there should not be at least a warning. It took me a long time to debug till I finally realized I had accidently declared 2 variables with the same name. Are there any reasons ?
Title: redeclaration
Post by: Pelle on April 27, 2006, 10:51:58 PM
Seems to be OK with the C standard. No bug, no warning.

(If you really need to catch this - why not intialize the variables? "int a = 0, a = 0;" is a different matter, and will cause an error...)

Pelle
Title: redeclaration
Post by: frankie on April 28, 2006, 04:47:39 PM
I don't see practical problems if the variable is the same, if you mean that the compiler accept the redeclaration and create different variables then we have a big problem.
Title: redeclaration
Post by: Pelle on April 29, 2006, 05:26:19 PM
It's the same...