Hello,
I am reading a book about introduction in C. I have a question about headers. At some point, the author give some hints about using header files in order to contain only function prototypes while the function definition is contained in another file, with the same name as the header but with extension .c instead of .h. More specifically, there are 3 files like so:
Code:
/*header.h*/
void fct(int i);
Code:
/*header.c*/
void fct(int i)
{
printf("Was here:> your number is %d", i);
}
Code:
/*main.c*/
#include "header.h"
int main(void)
{
int i=2;
fct(i);
return 0;
}
The problem with the above code is that the compiler complains that it cannot see the fct function from header.c, unless I insert a #include "header.c" line in header.h.
My question is - is it a way to use the code as it is and to avoid inclusion of header.c in header.h or main.c? Maybe some option passed to compiler in order for the compiler to see the definition of fct in the header.c file? I think it would be neat for the header.h file to contain only function prototypes and no #include directives.
Bookmarks