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
>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