As specified here C makes implicit declaration of functions it does not know. So I tend to make use of it for hiding implementation details. I defined the following header file:
#ifndef TEST_H
#define TEST_H
#define PRINT(msg) \
do{\
_print_info_msg(msg);\
printf(msg);\
} while(0)
#endif //TEST_H
and the corresponding C file:
#include "test.h"
void _print_info_msg(const char *str){
printf("INFO: printing %s\n", str);
}
When compiling this code compiler warns that implicit declaration of function ‘_print_info_msg’ [-Wimplicit-function-declaration]
.
The benefit of this I can see is that we do not directly expose helper function (_print_info_msg
) to anyone who includes test.h
yet we make use of linker so _print_info_msg
implementation is provided.
I'm not sure about this approach... Does it even make sense? To me it looks kind of ugly, but this is the only "use-case" I could find for implicit declaration.