While browsing the implementation of standard library headers in Visual Studio with C++ 20, I came across the type __int64
, it looked like a built-in type and I couldn't go to its definition. I googled it and found this article by Microsoft. Apparently the types __int32
, __int64
etc are Microsoft-specific built-in types.
I wondered why Microsoft uses these types instead of the non-Microsoft-specific int32_t
, int64_t
types, shouldn't they achieve the same thing? When I went to the definitions of those, they were just typedefs for types like int
and long long
, but I assume the implementation still guarantees that types like int32_t
have the amount of bits you'd expect. If these types/typedefs are good enough and reliable for the normal user, why does Microsoft use their own ones? If there's an advantage to using these types, why didn't they typedef int32_t
etc as __int32
etc? Is there a situation where I might want to use types like __int32
over int32_t
?
Because MSVC existed long before C++11 was introduced. For things that need a fixed size obviously they have to user their own internal type. That's why those have the __
prefix because the standard says that names beginning with double underscores are reserved in the global namespace
That's also the reason why lots of libraries define their own fixed-width types or even C and C++ keywords, for exampe gstreamer's guint32
, gint
..., OpenCL's cl_int
and cl_uint
..., Qt's quint32
, quint64
..., boost's boost::uint32_t
, zlib's z_off64_t
... because only decades after their advent, the standard stdint.h would come into existence
Other compilers do the same thing. For example GCC and Clang have __int128
because there's no int128_t
in the current standard. They also have _Decimal32
, _Decimal64
, __DEC32_MAX__
, __DEC128_MAX__
... before those were added to newer C and C++ standards