To paint the picture let's imagine we have a header called headertest.h and where going to use it in a file called test.c
It's context look like this
#include <stddef.h>
extern size_t string_lenght(const char *);
size_t string_lenght(const char *str)
{
size_t n = 0;
while (str[n] != '\0')
n++;
return (n);
}
It's purpose is to count the lenght of a given string and give output as size_t
if we include it in our test.c file like this and compile with gcc -o test test.c
#include "<location to header>/headertest.h"
int main ()
{
}
it compiles successfully and by running the command du -b test | awk '{print $1}' it outputs 16504, telling us it's size is 16504 bytes. However if we comment #include and just leave int main () and recompile test and run the same command again, we get 16464.
so in conclusion, how do you tell C to specifically only include a function when compiling only if it's present in the main C program, from a self made header file.
It is not uncommon to use pre-compiler defines in a header file to exclude code for one OS or another...