Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the logic of demangling?

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
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading