__func__ variable in C/C++

__func__ is a predefined variable to store the function name. It is defined as


static const char __func__[] = "function-name";

In g++ another available variable is __PRETTY_FUNCTION__ which store the function signature as well.
Code:

#include <stdio.h>

int add(int a, int b)
{
	printf("%s\n", __func__);
	printf("%s\n", __PRETTY_FUNCTION__);
	return (a+b);
}

int main()
{
	add(1,2);
}

Output:

add
int add(int, int)

Advertisements
__func__ variable in C/C++

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s