Is there a (standardized) way to get the name of the current method using c++?
Using GNU GCC you can do this by using the macro __FUNCTION__ and __PRETTY_FUNCTION__ (surrounded by 2 underscores), however, this is of course non portable. Is there a way to do this in standard c++ or a way to make it portable?
The
__func__identifier is part of the C99 standard and is in the C++0x draft.The identifier
__func__is implicitly declared by the compiler as if the following were at the very start of each function body:where
function-nameis an implementation-defined string automatically provided by the compiler.Until support for those standards is available (or more widely available) you’re stuck with compiler-specific gunk.