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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-03-18 
06:11:55 UTC ---
(In reply to comment #0)
> -------------------------------------------------------
> r.c:4:1: warning: data definition has no type or storage class [enabled by
> default]
> r.c:4:1: error: conflicting types for ‘c’
> r.c:3:6: note: previous declaration of ‘c’ was here
> r.c:4:5: warning: initialization makes integer from pointer without a cast
> [enabled by default]
> r.c:4:1: error: initializer element is not constant
> 


Since this is at the top level, only definitions are allowed which is what GCC
is assuming.  GCC has an extension of not needing a type or storage class for
some variable and assume int as the type.  That comes to the second error
message of the conflicting types.
The next warning is due to the int of c now being int from the extension.
And the last error message is saying the initializer element is not constant as
this is the top level.

That explains exactly what is going on and why GCC's warnings/error messages
are correct.
The trunk gives:
t1.c:4:1: warning: data definition has no type or storage class [enabled by
default]
 c = (int *)malloc(sizeof(int));
 ^
t1.c:4:1: error: conflicting types for ‘c’
t1.c:3:6: note: previous declaration of ‘c’ was here
 int *c;
      ^
t1.c:4:5: warning: initialization makes integer from pointer without a cast
[enabled by default]
 c = (int *)malloc(sizeof(int));
     ^
t1.c:4:1: error: initializer element is not constant
 c = (int *)malloc(sizeof(int));
 ^

Which should better explain what is going on here.

Reply via email to