This simple code (MCVE):
#include <stdio.h>
int a = 3;
int main(){
printf("%d\n", a);
return 0;
}
int a;
To my surprise, GCC (MinGW GCC 4.8.2, 4.9.2 and 6.3.0) gives no error, not even a warning about the marked line! However, if I assign a value a
in the second definition.
More strange, g++
it tells me that the second re-definition is a mistake, but gcc
does not work.
Is this a redefinition of an existing variable, since there is no keyword extern
?
source
share