c++linuxwindowsclangtypeid

Diffrent typeid between platforms


I don't understand why this programs produces differents outputs between Linux and Windows using the same compiler. In Windows it outputs float and in Linux it outputs f.

#include <typeinfo>
#include <iostream>

int main() {
        std::cout << typeid(float).name() << std::endl;
        return 0;
}

Solution

  • The typeid operator returns the name from the std::type_info, which is described as

    The class type_info holds implementation-specific information about a type, including the name of the type and means to compare two types for equality or collating order. This is the class returned by the typeid operator.

    So it is implementation-specific how they choose to name the types. This is reinforced again in std::type_info::name

    Returns an implementation defined null-terminated character string containing the name of the type. No guarantees are given; in particular, the returned string can be identical for several types and change between invocations of the same program.