Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
May 30, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

A macro returning the current function's name

Is there a macro that returns the name of a function which calls the macro? If not, how can I define such a macro?

Yes and no. The newly approved C99 standard defines the reserved variable __FUNCTION__ as the name of the current function. However, only few compilers support this feature. Two such compilers are GCC and Borland's C++ Builder 5.0. The latter uses a different name, though: __FUNC__ but it has the same functionality. As an aside, these variables aren't implemented as macros; they are variables. Macros are defined by the preprocessor, which knows very little about C++ constructs such as functions and blocks. Therefore, __FUNCTION__ can't be a macro.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date