Question

I used typeid to get the type names of the std::vector::size_type and a zero sized class A with the following code (cppreference):

#include<iostream>
#include <vector>
#include <typeinfo>

using namespace std;

class A {};

int main()
{
    vector<int> v(10); 

    vector<int>::size_type s = v.size(); 

    A a; 

    cout << typeid(s).name() << endl;
    cout << typeid(a).name() << endl;

};

And I got this as output:

m
1A

I guess that "1" before "A" is a result of the Empty Base Class Optimization, but what does "m" stand for and is this normal?

I am using the following gcc version: g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3

Was it helpful?

Solution

G++ uses implementation-defined naming for the types, but it also offers the utility c++filt to make them human-readable:

$ ./test | c++filt -t
unsigned long
A

OTHER TIPS

The quick hack I use on gcc to check types is a templated function with a forwarding reference parameter, printing __PRETTY_FUNCTION__:

template<typename T>
void PrintType(T&&) {
    cout << __PRETTY_FUNCTION__ << endl;
}

This might print something like:

void PrintType(T&&) [with T = long unsigned int]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top