I know that header files have forward declarations of various functions, structs, etc. that are used in the .c file that 'calls' the #include, right? As far as I understand, the "separation of powers" occurs like this:
Header file: func.h
contains forward declaration of function
int func(int i);
C source file: func.c
contains actual function definition
#include "func.h" int func(int i) { return ++i ; }
C source file source.c (the "actual" program):
#include <stdio.h>
#include "func.h"
int main(void) {
int res = func(3);
printf("%i", res);
}
My question is: seeing that the #include is simply a compiler directive that copies the contents of the .h in the file that #include is in, how does the .c file know how to actually execute the function? All it's getting is the int func(int i);, so how can it actually perform the function? How does it gain access to the actual definition of func? Does the header include some sort of 'pointer' that says "that's my definition, over there!"?
How does it work?