__FUNC__

From Appmethod Topics
Jump to: navigation, search

Go Up to Predefined Macros


Description

__FUNC__ is implemented as a predefined macro that represents the name of the current function.

__FUNCTION__ is equivalent to __FUNC__.

Examples

#include <tchar.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[]) {
	printf("You are in function %s\n", __FUNC__);
	return 0;
}

The __FUNC__ macro is also valid when used in a class method:

#include <iostream>

class TSomeClass {
public:
	void SomeMethod(void) {
		std::cout << "You are in the class member " << __FUNC__ << std::endl;
	}
};

int main() {
	TSomeClass SomeClass;
	SomeClass.SomeMethod();
	return 0;
}

However, this macro is not valid when declared using global scope. __FUNC__ outside of a function scope will have an indeterminate string value.

Here is an example of such incorrect usage:

#include <stdio.h>

char * funcStr = __FUNC__;

int main() {
	printf("You are in function %s\n", funcStr); // Won’t work as expected
	return 0;
}