I have a code like this. The code is working
I understand that the code prints ‘m’ because of demangling (https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html)
But why does compiler print ‘m’ for size_t?
What is the logic of mapping (‘i’ –> int // it’s clear, but why ‘m’ –> size_t)
#include <typeinfo>
using namespace std;
int main() {
size_t i = 5;
cout << "Type: " << typeid(i).name() << '\n'; // Type: m
}
>Solution :
If you check the itanium ABI you’ll see that all the unsigned types use the next letter in the alphabet after their signed equivalent (except char). int is i, unsigned int is j. long is l and unsigned long is m. As size_t isn’t an itanium type it’s represented by unsigned long and therefore m.
The assigned letters are essentially arbitrary so though there is some logic to their assignment they’re not really important exactly what they are. They’re an implementation detail and are platform specific, if you need to know what they mean use a demangler like c++filt, http://demangler.com/ or abi::__cxa_demangle