What's the difference between __PRETTY_FUNCTION__
, __FUNCTION__
, __func__
, and where are they documented? How do I decide which one to use?
C++ – What’s the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__
ccompiler-constructionstandards
Related Topic
- C++ – What are the differences between a pointer variable and a reference variable in C++
- C++ – the difference between g++ and gcc
- C++ – When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used
- C++ – The Definitive C++ Book Guide and List
- C++ – the difference between const int*, const int * const, and int const *
- C++ – What are the basic rules and idioms for operator overloading
- C++ – Difference between `constexpr` and `const`
Best Answer
__func__
is an implicitly declared identifier that expands to a character array variable containing the function name when it is used inside of a function. It was added to C in C99. From C99 §6.4.2.2/1:Note that it is not a macro and it has no special meaning during preprocessing.
__func__
was added to C++ in C++11, where it is specified as containing "an implementation-defined string" (C++11 §8.4.1[dcl.fct.def.general]/8), which is not quite as useful as the specification in C. (The original proposal to add__func__
to C++ was N1642).__FUNCTION__
is a pre-standard extension that some C compilers support (including gcc and Visual C++); in general, you should use__func__
where it is supported and only use__FUNCTION__
if you are using a compiler that does not support it (for example, Visual C++, which does not support C99 and does not yet support all of C++0x, does not provide__func__
).__PRETTY_FUNCTION__
is a gcc extension that is mostly the same as__FUNCTION__
, except that for C++ functions it contains the "pretty" name of the function including the signature of the function. Visual C++ has a similar (but not quite identical) extension,__FUNCSIG__
.For the nonstandard macros, you will want to consult your compiler's documentation. The Visual C++ extensions are included in the MSDN documentation of the C++ compiler's "Predefined Macros". The gcc documentation extensions are described in the gcc documentation page "Function Names as Strings."