devxlogo

The New __FUNCTION__ Macro

In addition to the traditional macros __DATE__, __LINE__, and __FILE__, which are defined by ANSI C, the new C9X Draft Standard also defines the macro __FUNCTION__.

__FUNCTION__ is expanded as the actual name of the function in which it is used, which makes it useful for reporting runtime errors and assertions. For example, the following function prints “failed in do_something” when the if-condition is true:

                    void do_something()   {     if (successful != OK)       printf("failed in %s", __FUNCTION__);      else     {/*...*/}   } 

Several compilers such as GCC and Dev-C++ already support this new macro. Other compilers (MS Visual C++, Borland’s C++ Builder) will probably follow suit once the C9X Draft Standard is approved.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

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.