I have the following source code which interests me.
#include <stdio.h> extern int foo; int foo = 32; int main() { printf("%d", foo); }
This a perfectly normal piece of code, and when I compile it with
gcc -Wall -Wextra -pedantic foo.c
I get no warnings.
And it seems weird, because a variable is defined both as external, and also global in the same file. I m quite sure that it s easy to the linker to find the reference for the external variable in the same file, but doesn t it look like a coding error? And if so, why doesn t the compiler warn about this?