A macro returning the current function’s name

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.

See also  How College Students Can Shape the Future of Tech Responsibility

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist