Last Ray of Hope Home of Kaluriel Hargrove

12Jun/09Off

Athena: XBox 360 Pad and Mac OS X

Along the way I also found a new "magic" variables, "__FUNCTION__" and "__PRETTY_FUNCTION__". These two variables can be used to retrieve the name of the function they are called for.

For example, this code will show both variables being used inside a C++ Class and a C Function.

//
//
class Test
{
public:
	//
	Test( int a )
	{
		printf( "Class:\n" );
		printf( "%s\n", __FUNCTION__ );
		printf( "%s\n", __PRETTY_FUNCTION__ );
	}
};
 
//
//
int main( int argc, char * argv[] )
{
	//
	printf( "Main:\n" );
	printf( "%s\n", __FUNCTION__ );
	printf( "%s\n", __PRETTY_FUNCTION__ );
 
	//
	printf( "\n" );
 
	//
	Test testClass( 2 );
 
	return 0;
}

 

And it will output the following to the console windows.

Main:
main
int main(int, char**)

Class:
Test
Test::Test(int)

As you can see the pretty function gives us not only the function name, but also the type of the params that are being passed to it. For some reason though using __PRETTY_FUNCTION__ in a Objective-C source file results in just __FUNCTION__.

Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.