Reputation: 695
So I am trying to get to grips with someone's code (and cannot contact them) and I do not understand why they do this. They call a function in main like this:
LOG_AddFunction();
This function is defined in a header file like this:
#define LOG_AddFunction() LOG_Add(LOG_TYPE_NORMAL, "%s()", __FUNCTION__)
Then LOG_Add is defined in the same header file:
extern int LOG_Add(LOG_TYPE eType, const char *pcText, ...);
There does not seem to be any ultimate definition of the LOG_AddFunction function and I do not understand why the code calls it. Can someone shed some light on this please?
Upvotes: 0
Views: 143
Reputation: 385114
LOG_AddFunction
is not a function. It is a function-like macro. Its only "definition" is exactly what you showed us in the question.
Its purpose is to automatically call LOG_Add
with the name of the function at the callsite (__FUNCTION__
) automatically passed. Whenever you write LOG_AddFunction()
, those characters are automatically replaced by the preprocessor (just as with any other macro) with LOG_Add(LOG_TYPE_NORMAL, "%s()", __FUNCTION__)
.
This saves typing the whole LOG_Add
call every time; nothing more.
Upvotes: 7