__FILE__
and __LINE__
are well known. There is a __func__
since C99.
#include <iostream> struct Foo { void Do(){ std::cout << __func__ << std::endl; } }; int main() { std::cout << __func__ << std::endl; Foo foo; foo.Do(); return 0; }
will output
main Do
Is there any macro / keyword that would output method name like Foo::Do
?
(C++11) The predefined identifier __func__ is implicitly defined as a string that contains the unqualified and unadorned name of the enclosing function. __func__ is mandated by the C++ standard and is not a Microsoft extension.
Boost has a special utility macro called BOOST_CURRENT_FUNCTION that hides the differences between the compiler implementations.
Following it's implementation we see that there are several macros depending on compiler:
__PRETTY_FUNCTION__
-- GCC, MetroWerks, Digital Mars, ICC, MinGW__FUNCSIG__
-- MSVC__FUNCTION__
-- Intel and IBM__FUNC__
-- Borland__func__
-- ANSI C99__FUNCTION__
and __PRETTY_FUNCTION__
.__FUNCSIG__
and __FUNCTION__
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With