I know I can rely on sizeof(char) == 1
, but what about sizeof(uint32_t)
and sizeof(uint8_t)
?
Shouldn't it be 32bit (8bit) in size guessing from the name?
Thanks!
uint32_t is a numeric type that guarantees 32 bits. The value is unsigned, meaning that the range of values goes from 0 to 232 - 1.
UInt32: This Struct is used to represents 32-bit unsigned integer.
Absolutely not, at least with regards to sizeof(uint32_t)
.
sizeof
returns the number of bytes, not the number of bits,
and if a byte is 16 bits on the platform, sizeof(uint32_t)
will be 2, not 4; if a byte is 32 bits (and such platforms
actually exist), sizeof(uint32_t)
will be 1 (and uint32_t
could be a typedef to unsigned char
).
Of course, in such cases, uint8_t
won't be defined.
The fixed-sized types will always be exactly that size. If you're on some weird platform that doesn't have integer types of that size then they will be undefined.
Note that it doesn't necessarily follow that sizeof(uint32_t) == 4
, if CHAR_BIT != 8
; again this only occurs on weird platforms.
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