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
May 30, 2000

A macro returning the current function's name

Question:
Is there a macro that returns the name of a function which calls the macro? If not, how can I define such a macro?

Answer:
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.

DevX Pro
 
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