In header file "foo.h", there is the following statement,
int foo;
In source file "a.c" and "b.c", the header file is included.
#include "foo.h"
Are there two independent foo's in two places or there is only one foo shared across "a.c" and "b.c"? I see this happens in a shared piece of code from others. Thanks in advance if you can understand this.
You will get an error by defining an external object multiple times.
Use extern int foo; in the header file and int foo; in exactly one .c file.
The extern specifier (if there is no initializer) at file-scope declares without defining.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With