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


advertisement
 

Retrieve a Function's Name Programmatically -3 : Page 3


advertisement
Signatures and Decorated Names
The __FUNCTION__ facility was deigned with C in mind. However, C++ programmers often need additional information about their functions. Visual Studio 2005 supports two more facilities as a non-standard extension: __FUNCDNAME__ and __FUNCSIG__ which translate into a function's decorated name and its signature, respectively. A function's decorated name can be useful when you want to check whether two compilers share the same ABI, for instance. Additionally, it can help you decipher cryptic linker errors. The intrepid among you may even use it to invoke a function with C++ linkage from a DLL! In the following example, show_name() reports the decorated name of a function:

void myfunc() { show_name(__FUNCDNAME__); //output: ?myfunc@@YAXXZ }

A function's signature consists of the function's name, its parameter list, return type, and enclosing namespace(s). If it's a member function, its class name and const/volatile qualifiers are also part of the signature. The following code demonstrates the signature differences between two functions: a freestanding function and a const member function. Both functions have the same name, return type and parameter:

void myfunc() { show_name(__FUNCSIG__); // void __cdecl myfunc(void) } struct S { void myfunc() const { show_name(__FUNCSIG__); //void __thiscall S::myfunc(void) const } };



Danny Kalev is a certified system analyst and software engineer specializing in C++. He was a member of the C++ standards committee between 1997 and 2000 and has since been involved informally in the C++0x standardization process. He is the author of "The ANSI/ISO Professional C++ Programmer's Handbook" and "The Informit C++ Reference Guide: Techniques, Insight, and Practical Advice on C++."
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap