The New __FUNCTION__ Macro

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.

See also  How to Block Websites During Certain Hours on a Mac Computer

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