I'm looking at stdint.h and given that it has uint16_t and uint_fast16_t, what is the use for uint_least16_t what might you want that couldn't be done equally well with one of the other two?
uint_least16_t the smallest thing that is capable of holding a uint16. uint_fast16_t the fastest thing that is capable of holding a uint16. uint16_t exactly a uint16, unfortunately may not be available on all platforms, on any platform where is is available uint_least16_t will refer to it.
However, uint16_t says that you must be given an integer that is unsigned and exactly 16 bits. Unsigned short says that you will be given an unsigned value that is at least 16 bits, but could be more than 16 bits. This is more useful for int32_t, uint32_t, int64_t, and uint64_t since those vary more by the system.
uint16_t is unsigned 16-bit integer. unsigned short int is unsigned short integer, but the size is implementation dependent. The standard only says it's at least 16-bit (i.e, minimum value of UINT_MAX is 65535 ).
uint_fast16_t should be used when you're writing code for C99 (or later) that needs an unsigned integer type that is at least 16 bits wide, chosen to make operations as fast as possible.
Say you're working on a compiler with:
unsigned char
is 8 bitsunsigned short
is 32 bitsunsigned int
is 64 bitsAnd unsigned int is the 'fastest'. On that platform:
uint16_t
would not be availableuint_least16_t
would be a 32 bit valueuint_fast16_t
would be a 64 bit valueA bit arcane, but that's what it's for.
How useful they are is another story - I see the exact size variants all the time. That's what people want. The 'least' and 'fast' versions I've seen used pretty close to never (it's possible that it was only in example code - I'm really not sure).
Ah, the link Patrick posted includes this "The typedef name uint_leastN_t designates an unsigned integer type with a width of at least N, such that no unsigned integer type with lesser size has at least the specified width."
So my current understanding is:
uint_least16_t the smallest thing that is capable of holding a uint16
uint_fast16_t the fastest thing that is capable of holding a uint16
uint16_t exactly a uint16, unfortunately may not be available on all platforms, on any platform where is is available uint_least16_t will refer to it. So if it were guaranteed to exist on all platforms we wouldn't need uint_least16_t at all.
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