Topic
  • No replies
SystemAdmin
SystemAdmin
196 Posts

Pinned topic Problem with function Demangle()

‏2010-04-26T07:05:00Z |
Hi,

AIX ep5710g 3 5 00C58FE04C00
IBM XL C/C++ Enterprise Edition V8.0 for AIX
Version: 08.00.0000.0014
//<hr />
aix53_demangle.cpp<hr />

#include <string>
#include <iostream>
#include <typeinfo>
#include <demangle.h>
int main()
{
std::string str = typeid(int).name();
char *rest;
Name *name = Demangle((char*)str.c_str(), rest) ;
if (name)
{
std::cout << name->Kind() << std::endl; <br />
std::cout << name->Text() << std::endl; <br />
}
else
{
std::cout << "Unable to demangle" << std::endl; <br />
}
return 0;
}

//<hr />

xlC_r -q64 -qwarn64 aix53_demangle.cpp
./a.out

Unable to demangle
// ===========
What is wrong?
Thanks,
Alex
Attachments:
aix53_demangle.cpp
Updated on 2010-04-26T14:21:27Z at 2010-04-26T14:21:27Z by camorton
  • camorton
    camorton
    10 Posts

    Re: Problem with function Demangle()

    ‏2010-04-26T13:45:59Z  

    from the manual
    To demangle a name (represented as a character array), create a
    dynamic
    instance of the Name class, providing the character
    string to the
    class's constructor. For example, if the compiler mangled X::f(int) to
    the mangled name f__1XFi, in order to demangle the
    name, use the
    following code:

    char *rest;
    Name *name = Demangle("f__1XFi", rest) ;

    *If the supplied character string is not a name that requires
    demangling,
    because the original name was not mangled, the Demangle
    function
    returns NULL.*
    You are trying to demangle "int" which does not need to be demangled, so it returns NULL.

  • SystemAdmin
    SystemAdmin
    196 Posts

    Re: Problem with function Demangle()

    ‏2010-04-26T14:03:49Z  
    • camorton
    • ‏2010-04-26T13:45:59Z

    from the manual
    To demangle a name (represented as a character array), create a
    dynamic
    instance of the Name class, providing the character
    string to the
    class's constructor. For example, if the compiler mangled X::f(int) to
    the mangled name f__1XFi, in order to demangle the
    name, use the
    following code:

    char *rest;
    Name *name = Demangle("f__1XFi", rest) ;

    *If the supplied character string is not a name that requires
    demangling,
    because the original name was not mangled, the Demangle
    function
    returns NULL.*
    You are trying to demangle "int" which does not need to be demangled, so it returns NULL.


    It's also worth noting that, unfortunately, the result of std::type_info::name is implementation defined. Some other compilers (ie, the Gnu compiler) output the mangled name which is likely where the confusion comes from.
  • SystemAdmin
    SystemAdmin
    196 Posts

    Re: Problem with function Demangle()

    ‏2010-04-26T14:11:20Z  

    It's also worth noting that, unfortunately, the result of std::type_info::name is implementation defined. Some other compilers (ie, the Gnu compiler) output the mangled name which is likely where the confusion comes from.
    Thank you.
  • SystemAdmin
    SystemAdmin
    196 Posts

    Re: Problem with function Demangle()

    ‏2010-04-26T14:18:56Z  
    Thank you.
    You are right.

    For instance, result of std::type_info::name on compiler aCC (HP-UX) is mangled name.
    Result of std::type_info::name on compiler xlC (AIX) is demangled name
    The confusion came from that.
    Thank you.
    Updated on 2010-04-26T14:18:56Z at 2010-04-26T14:18:56Z by SystemAdmin
  • camorton
    camorton
    10 Posts

    Re: Problem with function Demangle()

    ‏2010-04-26T14:21:27Z  
    You are right.

    For instance, result of std::type_info::name on compiler aCC (HP-UX) is mangled name.
    Result of std::type_info::name on compiler xlC (AIX) is demangled name
    The confusion came from that.
    Thank you.
    Now I've learned something new as well. Thanks.