Reputation: 5653
The question is actually somewhat broader.
Based on the last 15 years experience I currently assume that size of types is as follows:
byte = 8 bit
short = 2 bytes
int = 4 bytes
long long = 8 bytes
Is there a modern OS where this assumption can be challenged?
Upvotes: 11
Views: 801
Reputation: 3737
You have pretty much platforms (especially in embedded) where it is not. You e.g. can have 2-octet char.
Upvotes: 0
Reputation: 9428
There is probably one exception.
long long = error
I've heard there are problems with old Microsoft C compilers. I've seen some workarounds in source code. However Microsoft 32-bit C/C++ Optimizing Compiler Version 16 (from Visual Studio 2010) do have long long.
Upvotes: 0
Reputation: 45173
Whether or not such "modern" systems exist, you should static_assert
assert those assumptions in your code so that if your code is ever ported to a platform where the assumption is incorrect, the person doing the porting will be alerted to the problem immediately.
Upvotes: 4
Reputation: 42607
The standard is intentionally vague on this subject, only specifying:
C90: sizeof(short) <= sizeof(int) <= sizeof(long)
C99: sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
Furthermore, C99 only requires that int be at least a 16-bit value.
Also, 'byte' is not a C datatype.
Upvotes: 3