Home > Blockchain >  What is the logic of demangling?
What is the logic of demangling?

Time:01-29

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
}

CodePudding user response:

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

CodePudding user response:

But why does compiler print 'm' for size_t?

Because size_t is an unsigned long on this platform and the letter m represents unsigned long in this compiler on this platform.

What is the logic of mapping ('i' --> int // it's clear, but why 'm' --> size_t)

There is no "logic", there are just rules laid out what letter is what type. See https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin .

  • Related