This is file "1.c"
#include <stdio.h>
char foo;
int bar(){
}
int main(){
printf("%d",foo);
return 0;
}
//--------------------------
This is file '2.c'
void foo(){
}
Compiler invoked as gcc 1.c 2.c
Does the above gives an undefined behaviour? My guess is, yes. Otherwise it's almost impossible to do optimization.
Multiple different definitions for the same entity (class, template, enumeration, inline function, static member function, etc.) [What are all the common undefined behaviour that a C++ programmer should know about?
But as far as I know char foo
produce only a weak symbol that can be overridden by void foo(){} at linkage. Furthermore, if I change char foo
into extern char foo
, is that still a definition?