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
The typeid operator returns an lvalue of type const std::type_info that represents the type of expression expr. You must include the standard template library header <typeinfo> to use the typeid operator.
@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.
std::type_info The class type_info holds implementation-specific information about a type, including the name of the type and means to compare two types for equality or collating order.
typeof is a GNU extension, and gives you the type of any expression at compile time. This can be useful, for instance, in declaring temporary variables in macros that may be used on multiple types. In C++, you would usually use templates instead.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With