Search code examples
c++autobitset

what is the name of bitset telling me?


Here is a trivial code snippet to give the name of auto date types. So then I was wondering what bitset would have for an identifier. it returns : "St6bitsetILm32EE". Ok, bitset is the datatype, 32 is the size, Im not sure what else the name is telling me. I don't know what St6, I, LM, or EE are referring to. Clarification would be nice.

// C++ program to demonstrate working of auto 
// and type inference 
#include <bits/stdc++.h> 
using namespace std; 
#define M 32  
int main() 
{ 
    auto x = 5;    //i for integer
    auto y = 3.37; //D for double
    auto ptr = &x; //Pi for pointer
    auto z = "WTF";//PKc for string or char**
    bitset <M> bset(2);
    auto k = bset; //bitset :: St6bitsetILm32EE  
     cout << typeid(x).name() << endl 
         << typeid(y).name() << endl 
         << typeid(k).name() << endl 
         << typeid(ptr).name() << endl 
         << typeid(z).name() << endl; 

    return 0; 
} 

pardon my comments, I literally just learned about the auto datatype.


Solution

  • Names in C++ are mangled.

    I am guessing the name has been mangled mangled according to Itanium C++ ABI rules. The rules specify how each type/identifier/function name is mangled. From that you can try to manually demangle the type:

    • St is <substitution>. It's used to compress ::std:: namespace prefix.
    • 6 is <number>. It encodes then length of the following identifier. Next 6 characters make the identifier.
    • bitset is <identifier>. It has 6 characters. It's the identifier of this class.
    • I starts <template-args>. It it the list of template arguments.
      • Then follows one <template-arg>
      • L starts <expr-primary>.
        • m is <type>. This is the type of template argument, not it's value. m means the type is unsigned long.
        • 32 is the value passed as template parameter. 32 is not the size here.
      • E ends <expr-primary>.
    • E ends <template-args>.

    So St6bitsetILm32EE is a mangled name for type ::std::bitset<(unsigned long)32>.