Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__func__ C++11 function's local predefined variable, won't compile

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?

like image 414
CodeBricks Avatar asked Feb 28 '13 02:02

CodeBricks


People also ask

What is__ func__ in c++?

“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.

Is __ function __ standard?

__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 ...

What is pretty function C++?

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.

Which are the predefined identifiers?

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.


1 Answers

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

like image 137
congusbongus Avatar answered Sep 30 '22 16:09

congusbongus