Thread: azone2 question
View Single Post
  #1  
Old 01-29-2012, 05:05 AM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

The C, and consequentially C++ standard only requires that a type have a minimum size, not a maximum. An unsigned long is guaranteed to hold a value of 0 to 4294967295, which requires 32 bits. An unsigned int is guaranteed to hold a value of 0 to 65535, or 16 bits, but on most 32-bit platforms it is 32 bits as well because that is the fastest register size on that platform.

In your case, it's clear that unsigned long is 64-bits. As far as I know, on Linux, an unsigned int is 32 bits for both 32-bit and 64-bit programs. On Windows, unsigned long is also 32 bits for both.

C99 and C++ 11 define various guaranteed size types, but multiplatform support for both standards is a bit sketchy, so if you go down that road you may run into problems. I believe GCC has supported the C99 types for a while, but Visual Studio did not include the header until VC++ 10.

If you're really lucky, when you change that to unsigned int you'll get 12, 4, 4, 8 as the output from that program which is what you're looking for. If the offsets are different than that you'll need to add #pragma pack(push, 1), #pragma pack(pop) around the struct definition to force it.
Reply With Quote