This is a stupid question, I admit. The code will explain this better. Got these files:
hello.c:
#include <stdio.h> void hello(char * s) { printf("hello, %s\n", s); }
main.c:
int main() { hello("world!"); return 0; }
Makefile:
test : main.o hello.o gcc -o test main.o hello.o main.o : main.c gcc -c main.c hello.o : hello.c gcc -c hello.c .PHONY : clean clean : -rm test -rm main.o -rm hello.o
I can just do and .test, and it works. Should I include something like hello.h in main.c so that the compiler knows the function prototype?
I haven't even turned on hello.c anywhere, and it just works! Why does main.c know about the hello function?
If this works, when do I need .h files? I am new to C programming, but I thought this concept was easy to understand, now I'm completely confused.
source share