The end of unsized integers

In recent versions of the Mac OS SDK, Apple has largely moved away from datatypes such as int and long as they have different meanings in 64 bit OSes. In a project I’m working on, this bit me twice recently. The first is that a UINT (the code was ported from Windows) was incorrectly typed to be a byte or a dword (2 bytes) when it should have been 4 bytes. If the type was a UINT32 (UInt32 in Mac speak), setting the correct type would have been easy and not confusing. Likewise, there was another case where a variable was typed as unsigned long long which was 8 bytes on a 32 bit OS, but 16 bytes on a 64 bit OS (if I’m off on the values, please forgive me). If it was specified as UInt64, that is completely unambiguous and a bug would not have occurred.

So, this day forward, I’m going to do my absolute best to only use sized integers, like SInt32, UInt32, etc. where the exact size is specified. This will be much more important using both 32 bit and 64 bit versions of Mac OS X. Granted, for many developers, it still doesn’t matter, but I’ve dealt a lot of USB communications and structures, so the size of the integers makes a huge difference.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.