Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Oct 26, 1999

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.
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


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

 

 

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