Using and Porting GNU CC - Function Names

Node: Function Names Prev: Incomplete Enums Up: C Extensions

Function Names as Strings

GNU CC predefines two string variables to be the name of the current function. The variable __FUNCTION__ is the name of the function as it appears in the source. The variable __PRETTY_FUNCTION__ is 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. For example, this program:

	extern "C" {
	extern int printf (char *, ...);
	}
	
	class a {
	 public:
	  sub (int i)
	    {
	      printf ("__FUNCTION__ = %s\n", __FUNCTION__);
	      printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
	    }
	};
	
	int
	main (void)
	{
	  a ax;
	  ax.sub (0);
	  return 0;
	}

gives this output:

	__FUNCTION__ = sub
	__PRETTY_FUNCTION__ = int  a::sub (int)


Up: C Extensions