I want to output the function name each time it is called, I can easily copy and paste the function name, however I wondered if there was a shortcut that would do the job for me
I see from your example that you are using Qt. In which case your best bet is to use Q_FUNC_INFO
found in <QGlobal>
. Here's the description:
Expands to a string that describe the function the macro resides in. How this string looks more specifically is compiler dependent. With GNU GCC it is typically the function signature, while with other compilers it might be the line and column number.
__func__
is c99 ( which does in turn mean it might not work with visual studio - but hey it's standard :o) )
__FUNCTION__
works pretty much everywhere
__PRETTY_FUNCTION__
is gnu specific and returns the full qualified name with (namespaces?), classname, returntype, functionname, parameterslist
If you check out boost there is a macro BOOST_CURRENT_FUNCTION that is portable across platforms. In the C99 standard there is a compiler variable __func__
that has the desired effect. I believe has been accepted into the C++0x standard. A reasonable number of compilers will already support this.
"__FUNCTION__
" is supported by both MSVC and GCC and should give you the information you need.
If you are using gcc you may find __PRETTY_FUNCTION__
more to your liking.