WEBINAR:
On-Demand
Application Security Testing: An Integral Part of DevOps
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
}
};