After some talking about linking in ##C on irc.freenode.net, I went to test some concepts I learned, and came up with this situation.
I have this file, named main.c:
int main(void) {
func();
return 0;
}
And this file, named test.c:
#include <stdio.h>
void func(void) {
printf("Hello.\n");
}
There’s no test.h file.
I do this:
$ gcc -c main.c
$ gcc -c test.c
$ gcc main.o test.o
$ ./a.out
Hello.
$
and that works. Shouldn’t gcc complain, on its first call, about not knowing function func() that is called in the main.c file? I didn’t include any file with its prototype or implementation, and yet gcc can compile an object code and make a sane executable. What happened there that I’m missing?
Thank you.
Turn on a few warnings and you will be made painfully aware of the problems.
C will by default assume things about unknown functions. Good? Probably not. Historical.
Also
gcc -std=c99will throw the warning as well.