Monday, June 20, 2011


C++ 2011 and __func__



So what happens to __func__ in different scopes? How about GCC's extension for pretty function names?

#include <iostream>
using namespace std;

namespace
{
void f()
{
auto func = []()->const char *{ return(__func__); };
auto func2 = []()->const char *{ return(__PRETTY_FUNCTION__); }; //GCC extension

cout << func() << '\n'
<< func2() << '\n'
<< __func__ << '\n'
<< __PRETTY_FUNCTION__ << endl;
}
}

int main()
{
f();
cout << __func__ << '\n'
<< __PRETTY_FUNCTION__ << endl;

return(0);
}



Output:

/tmp> g++-4.5 -Wall -o test test.cpp -std=c++0x
/tmp> ./test
operator()
<unnamed>::f()::<lambda()>
f
void<unnamed>::f()
main
int main()
/tmp>

/tmp> g++-4.6 -Wall -o test test.cpp -std=c++0x
/tmp> ./test
operator()
{anonymous}::f()::<lambda()>
f
void {anonymous}::f()
main
int main()
/tmp>

9 comments:

henke37 said...

You got me there, I have no idea what the top two tests are supposed to mean.

And here I thought that I knew how c++ syntax looks like.

ahihi said...
This comment has been removed by the author.
bamgosoo said...


I used to be suggested this blog by means of my cousin.
I am not sure whether or not this put up is
written by means of him as nobody else recognize such unique about my problem.
You are wonderful! Thank you!

My web page::; 안마
(jk)

MBBS in Philippines said...

Wisdom Overseasis authorized India's Exclusive Partner of Southwestern University PHINMA, the Philippines established its strong trust in the minds of all the Indian medical aspirants and their parents. Under the excellent leadership of the founder Director Mr. Thummala Ravikanth, Wisdom meritoriously won the hearts of thousands of future doctors and was praised as the “Top Medical Career Growth Specialists" among Overseas Medical Education Consultants in India.

Southwestern University PHINMAglobally recognized university in Cebu City, the Philippines facilitating educational service from 1946. With the sole aim of serving the world by providing an accessible, affordable, and high-quality education to all the local and foreign students. SWU PHINMA is undergoing continuous changes and shaping itself as the best leader with major improvements in academics, technology, and infrastructure also in improving the quality of student life.

Easy Loan Mart said...

Hi....
__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.
You are also read more Online Loan for Business Expansion

toto365prokt said...

스포츠토토티비 Usually I don’t learn post on blogs, but I would
like to say that this write-up very compelled me to check out and do it!
Your writing style has been amazed me. Thanks, very nice article.

toto365prokt said...

I really like your blog.. very nice colors & theme. Did you make
this website yourself or did you hire someone
to do it for you? Plz answer back as I’m looking to design my own blog and would like to know where u
got this from. thanks 스포츠토토

toto365prokt said...

these websites are really needed, you can learn a lot. 카지노사이트

Error Code Expert said...

Your article is very good, I have read many articles but I am really impressed with your posts. Thank you, I will review this article. To know about me, try talking to me. for More Information Visit Here:- Install Epson Printer Driver on Mac