14

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

tmaric
  • 5,347
  • 4
  • 42
  • 75

2 Answers2

22

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
Cubbi
  • 46,567
  • 13
  • 103
  • 169
  • So, the name "m" is then reserved and fixed for vector::size_type (for g++)? – tmaric May 06 '13 at 10:31
  • @tomislav-maric the name "m" stands for `unsigned long`, which happens to be typedef for `std::size_t`, which happens to be the typedef for `std::vector<>::size_type`. Typedefs do not create new types. – Cubbi May 06 '13 at 10:33
  • I know they don't create new types, I meant this: is "m" then for G++ a name for "unsigned_long", and it is defined somewhere (compiler implementation?), so c++filt looks it up there, and maps it back to "unsigned_long"? – tmaric May 06 '13 at 10:35
  • 2
    @tomislav-maric Yes, `/usr/bin/g++` and `/usr/bin/c++filt` are part of the same compiler implementation. – Cubbi May 06 '13 at 10:43
1

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]

Don Reba
  • 13,814
  • 3
  • 48
  • 61