there is a function f in foo.c, I put f Prototypes into a header file.
and then, there are 3 question:
- does header file must named
foo.h? - does
foo.candfoo.hmust be in the same directory ? - If the answer to both questions is no, that is to say, a header file can named
f.h,foo.candf.hcan be in different directory. look a example:
~/cfile/foo.c
#include "~/hfile/f.h"
int f(void){
...
}
~/hfile/f.h
int f(void);
~/main/cmain.c
#include "~/hfile/f.h"
int main(void){
f();
...
}
Then, when I call f function in cmain.c, cmain.c can find f.h by #include directive, but how cmain.c find foo.c by f.h, because cmain.c only include f.h not include foo.c? or how the compiler or linker find foo.c by f.h?