tags:

views:

145

answers:

3

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?

A: 

It's part of the c standard. It doesn't need a good use case. :P

See this page and look for the section titled "Minimum-width integer types".

Patrick
+7  A: 

Say you're working on a compiler with:

  • unsigned char is 8 bits
  • unsigned short is 32 bits
  • unsigned int is 64 bits

And unsigned int is the 'fastest'. On that platform:

  • uint16_t would not be available
  • uint_least16_t would be a 32 bit value
  • uint_fast16_t would be a 64 bit value

A 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).

Michael Burr
+1  A: 

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.

tolomea
Yes - but uint16_t is not guaranteed to exist; think Cray (64-bit integers were all they had - int and long).
Jonathan Leffler
yeah... that'd be the bit where I said "unfortunately may not be available on all platforms"
tolomea