PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 17, 2022

[FIXED] Why does Microsoft use types like __int32 etc instead of int32_t?

 October 17, 2022     built-in-types, c++, integer, visual-c++     No comments   

Issue

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?


Solution

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

  • Why do so many libraries define their own fixed width integers?
  • Why do c++ libraries often define their own primitive types?


Answered By - phuclv
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing