Recently I've been poking around and trying to figure out how C compilers work.
I've noticed that different computers seem to exhibit different behaviours for the following actions:
// a.c
// #include"oui.h"
int main() {
oui();
}
// oui.h
void oui();
gcc -c a.c
On one computer, I am warned that function oui
in a.c
is undefined. This makes sense to me, and uncommenting the include fixes the problem.
On another computer, however, even with the include commented out, the compiler produces the object a.o
without complaint. This does not make sense to me, because isn't oui
undefined without the header file?
Which is the normal behaviour? Are some settings on one of my computers messed up?
Don't bother with the following questions if you don't want to, they just popped into my mind and I'll make another thread if need be :).
Side question: The -c
flag produces object files but does not link, so is there a special "link" flag afterwards to put the object files together, or is it just gcc
? Why not just gcc everything together at the start?
Side question #2: if I do gcc filea fileb filec
, is filea
inherently special for being the first argument? Or does the order of gcc not matter because the compiler finds whichever file has main
by itself?