• Forum
  • Lounge
  • C++ Name Mangling: Visual Studio vs. GCC

 
C++ Name Mangling: Visual Studio vs. GCC

closed account (E0p9LyTq)
I was reading the Boost documentation recently about the demangle header, and decided to try one of the examples.

To my surprise VSC++ 2015 apparently doesn't need the Boost libraries to demangle, it is done automatically. Here's the code I used for the test:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <boost/core/demangle.hpp>
#include <typeinfo>
#include <iostream>

template<class T> struct X
{
};

int main()
{
   std::cout << typeid(unsigned long).name() << "\n";
   std::cout << boost::core::demangle(typeid(unsigned long).name()) << "\n\n";

   const auto name = typeid(X<int>).name();

   std::cout << typeid(X<int>).name() << "\n";
   std::cout << boost::core::demangle(typeid(X<int>).name()) << "\n";
}


The output from VC++:

unsigned long
unsigned long

struct X<int>
struct X<int>


and the output from GCC 4.9.2:

m
unsigned long

1XIiE
X<int>


This is not code I need help with, just something I ran across that was a "gee, golly" moment.

This is not as serious as GCC not supporting std::random_device, but still something that is of note.
The return value of name() is implementation-defined, so I guess it makes sense they do whatever they like with the "actual" internal name.
closed account (E0p9LyTq)
I understand the actual implementation is not defined, as other parts of the C++ standard are, the details left up to the creators. I just thought it interesting the differences between two different compilers.
Last edited on
Visual Studio isn't unique: Oracle C++ and IBM XL C++ also produce human-readable type names.
closed account (E0p9LyTq)
@Cubbi,

Thank you for that particular insight. I don't use those tools so didn't know their implementation.

Out of 4 currently mentioned compilers it looks like GCC is "odd man out."

Curiouser and curiouser, I say. ;)
Topic archived. No new replies allowed.