Is it possible to get a pointer to the current function? If it is, how can I do so?
Motivation: I have a function doing some logging, and would like to call
log(currentfunc, "blabla")
Which does some output for example.
Is it possible to get a pointer to the current function? If it is, how can I do so?
Motivation: I have a function doing some logging, and would like to call
log(currentfunc, "blabla")
Which does some output for example.
You can obtain the name of the current function (but not a pointer to it) via the predefined identifier __func__
which is part of C99.
log(__func__, "blabla");
I'm not sure about the pointer to a function, but the predefined identifier __func__
returns the name of the function. Maybe that can help...
In fact, I'd replace your function log
with a macro so you don't have to paste in the name every time, as such:
#define log(x) log(__func__,x)