Printing the name of a function

Is it possible to print the name of the function from where the print method is being called? Go through the following pseudo code.

1
2
3
4
5
6
7
void foo (void)
{
	cout << XXX << endl;
	// XXX is some kind of macro, like __LINE__,
	// that contains the name of the current function.
	// i.e. void foo (void)
}


Similarly, in the context of C++, it is possible to print the name a class with typeid (*this).name (). But what about the name of a method?
Last edited on
I think that most compilers support __FUNC__, but it is not in the standard.
I got the answer. In general, it is __FUNCTION__. This works well both with gcc and vc2005. __func__ is not supported in vc2005.
In gcc, there is __PRETTY_FUNCTION__ which prints the entire name of the function, e.g. int Class::foo (int arg).

Thanks
Topic archived. No new replies allowed.