stdint.h in C99 contains many options for integer sizes, types and ranges - so many I donโt know which ones to choose!
I know how to use size_t and ptrdiff_t when necessary, and I use fixed size types for storage and transmission. My question is about values โโthat will only be stored in the memory of the host machine.
For example, the image structure may contain the following elements:
struct image { integer width, height; integer bits_per_pixel; ... };
If width and height never exceed SHRT_MAX , should I use short or stick with int ? Image cannot have negative width or height, so use an unsigned type? Perhaps (u)int_least16_t right choice? Something else?
If bits_per_pixel will never exceed 64, use char , unsigned char , uint8_t , int or something else?
What would you use in this example and why?
How does the processor architecture on which the code will run affect the choice? i.e. PPC or x86, 32 or 64 bit.
How does the device on which the code will work affect the choice? i.e. desktop, phone, console.
How does the choice depend on performance and optimization?
My question is in simple terms: how do you choose which integer to use?
c c99 integer size
xx
source share