assume there is a header file: a.h and source file : a1.c a2.c ... an.c; n>=1, which means it may only have one source file, or have several source files.
my question is that how to define a global variable g in a.h; which should be visible by a1.c ... an.c.
there are restrictions:
in a1.c a2.c ... an.c; "a.h" can only be included in the first line, which means there should be no code in the source file before the line of #include "a.h"
g must be defined in the a.h.
can only compile the code by the following way:
gcc -c a1.c -o a1.o ... gcc -c an.c -o an.o gcc -o a.exe a1.o ... an.o
there is an answer that define g in a.h like this: extern int g; however, according to the c's specification J.5.11; it's undefined behavior.
is there any other solution?