Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact-width integer types in C (stdint.h)

Tags:

c

integer

size

I would like char, short and int types to be 1, 2 and 4 bytes width. I have included a stdint.h header into my sources. Does this guarantee that int8_t, int16_t and int32_t integer types will be of widths specified? What is the best way to achieve this?

like image 683
ezpresso Avatar asked Apr 24 '26 17:04

ezpresso


1 Answers

If these types exist, they have the correct width and are encoded in two's complement.

Edit: you should be able to check if the types exist with something like

#ifdef INT32_MAX
...
#endif

but on all end user architectures (PC etc) these types do usually exist.

like image 65
Jens Gustedt Avatar answered Apr 27 '26 07:04

Jens Gustedt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!