The __func__
C++11 local predefined variable of a function does not compile in Visual Studio 2012 Professional (with Update 1 installed) with the default built-in Visual Studio 2012 (v110) compiler or the November 2012 CTP (v120_CTP_Nov2012) compiler. However, the editor does not complain with any red squiggly underline under __func__
. __func__
is supposed to give the name of its containing function, in this case foo
, but this neither compiles nor make the editor complain:
#include <iostream>
using namespace std;
void foo()
{
cout << __func__ << endl;
return;
}
int main()
{
foo();
return 0;
}
It gives the compiler error:
error C2065: '__func__' : undeclared identifier
Am I missing something in my code or will this work in a future update?
“The identifier __func__ shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declaration. static const char __func__[] = “function-name”; appeared, where function-name is the name of the lexically-enclosing function.
__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 ...
The identifier __PRETTY_FUNCTION__ holds the name of the function pretty printed in a language specific fashion. These names are always the same in a C function, but in a C++ function they may be different.
Predefined Identifier __func__ in C Identifier is the name given to an entity in programming to identify it in the program. Generally, identifiers are created by the programmer for efficient working but there are some predefined identifiers that are inbuilt in programming. For example, cout, cin, etc.
MSVC's C99 support is quite poor in general; your best bet might be to use the MSVC-specific __FUNCTION__
macro. See this question for details: Cross-platform defining #define for macros __FUNCTION__ and __func__
Update (2015-06-22): Visual Studio 2015 supports __func__
, see the blog post
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