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?
int is always 32 bits wide. sizeof(T) represents the number of 8-bit bytes (octets) needed to store a variable of type T .
In 32-bit operating systems, the int type is usually 32 bits, or 4 bytes. Thus, the int type is equivalent to either the short int or the long int type, and the unsigned int type is equivalent to either the unsigned short or the unsigned long type, depending on the target environment.
int is 32 bits in size. long , ptr , and off_t are all 64 bits (8 bytes) in size.
You can try sizeof(char*) , in general the pointer-to-char has the machine-size. If it's 8, then your machine is 64 bit, if 4, then 32.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With