1

I have used the following function in the past to demangle c++ symbols it has proved very useful:

char* __cxa_demangle(const char* __mangled_name, char* __output_buffer, size_t* __length, int* __status);

Now I work on a C application that uses gcc, but cannot use __cxa_demangle as it is a C program (it's only available with g++ the C++ compiler), in C++ I would have typically called as follows:

abi::__cxa_demangle(mangled.c_str(), NULL, 0, 0);

Anybody know how to achieve the same in C?

ericcurtin
  • 1,499
  • 17
  • 20
  • 1
    What is the purpose of a demangle feature in C? – mouviciel Sep 18 '19 at 09:25
  • 1
    That's probably another stackoverflow question in itself :) It demangles mangles function signatures, generated backtraces come with mangled names. Here is a wiki article on it :) https://en.wikipedia.org/wiki/Name_mangling – ericcurtin Sep 18 '19 at 09:27
  • OK, I see: this is a Microsoft thing followed by GCC when compiling for Windows. – mouviciel Sep 18 '19 at 09:38
  • 1
    This is relevant to all platforms. I have never used this on Windows, although I'm sure it's relevant there too. – ericcurtin Sep 18 '19 at 09:57

1 Answers1

4

Answering my own question it's in the comment of the source code:

   *  @note The same demangling functionality is available via
   *  libiberty (@c <libiberty/demangle.h> and @c libiberty.a) in GCC
   *  3.1 and later, but that requires explicit installation (@c
   *  --enable-install-libiberty) and uses a different API, although
   *  the ABI is unchanged.
   */
  char*
  __cxa_demangle(const char* __mangled_name, char* __output_buffer,
         size_t* __length, int* __status);
ericcurtin
  • 1,499
  • 17
  • 20