devxlogo

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.

devx-admin

Share the Post: