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

typeid(x).name() yields 'y', what does it mean?

In Code below, we get:
12 4
y
typeid().name should return data type,
but I cannot find which data type ‘y’ means 🤔

void alignment()
{
    struct Foo
    {
        int   i;
        float f;
        char  c;
    };

    std::cout << sizeof(Foo) << '\t' << alignof(Foo) << '\n';
    auto x = alignof(Foo);
    std::cout << typeid(x).name() << '\n';
}

I tried to find an association with data type names but nothing fits

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 :

I tried to find an association with data type names but nothing fits

Your compiler gave std::size_t name y, mine called it m, both are right and fully allowed to.
According to:
https://en.cppreference.com/w/cpp/types/type_info/name

Some implementations (such as MSVC, IBM, Oracle) produce a human-readable type name. Others, most notably gcc and clang, return the mangled name, which is specified by the Itanium C++ ABI. The mangled name can be converted to human-readable form using implementation-specific API such as abi::__cxa_demangle directly or through boost::core::demangle. It can also be piped through the command-line utility c++filt -t.

And alignof returns size_t, see here.

Example with demangling that using Boost:
https://godbolt.org/z/8959KdMhv

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