Reputation: 4288
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.
Upvotes: 4
Views: 1558
Reputation: 5657
You can use combination of __FILE__ and __LINE__. It will be work with Microsoft and GCC compilers.
Upvotes: 0
Reputation: 258648
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)
Upvotes: 2
Reputation: 133112
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");
Upvotes: 5