Cross-Platform Development and Data Type Sizes

One of the problems when developing cross-platform apps is the question how long the intrinsic data types are on the different platforms. A while ago I created a table with the sizes of the different data types on 32- and 64-bit Windows and Linux, both for C++ and C#/.NET. Since this might be useful for others (and for me when accessing this from a different computer :-)) I thought I’d share my table.

On 32bit Windows and on 32bit Linux, a short in C++ is 16 bit long, an int 32 bit, long 32 bit and pointers 32 bit. On 64bit Windows short, int and long are the same as on 32bit Windows, but pointers are 64 bit long. On 64bit Linux, a short is 16 bit, int 32 bit and long and pointers 64 bit.

Comparison of data type sizes:

 Windows 32bit  Linux 32bit  Windows 64bit  Linux 64bit
C++ bool 1 byte 1 byte 1 byte 1 byte
C++ short 2 bytes 2 bytes 2 bytes 2 bytes
C++ int 4 bytes 4 bytes 4 bytes 4 bytes
C++ long 4 bytes 4 bytes 4 bytes 8 bytes
C++ void * 4 bytes 4 bytes 8 bytes 8 bytes
C++ char 1 byte 1 byte 1 byte 1 byte
C++ wchar_t 2 bytes 4 bytes 2 bytes 4 bytes
C# bool 4 bytes 4 bytes 4 bytes 4 bytes
C# byte 1 byte 1 byte 1 byte 1 byte
C# short 2 bytes 2 bytes 2 bytes 2 bytes
C# int 4 bytes 4 bytes 4 bytes 4 bytes
C# long 8 bytes 8 bytes 8 bytes 8 bytes
C# IntPtr 4 bytes 4 bytes 8 bytes 8 bytes
C# char 1 byte 2 bytes 1 byte 2 bytes

Note: I didn’t have a 64bit Windows machine to do these tests, that’s why there are some holes. The values that are there for 64bit Windows are from the documentation; all other values were retrieved experimentally.

Edit 2017-04-27: Updated table with values for 64bit Windows, added values for bool and byte

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s