Re: Why in stdint.h have both least and fast integer types?
From: Kevin Bracey (kevin.bracey_at_tematic.com)
Date: 12/01/04
- Next message: Anand Hariharan: "Kernighan on Pascal (WAS Re: Learning C with Older books ?)"
- Previous message: Andrey Tarasevich: "Re: compiler won't allow dimensioned array of Char* to be signed to another???"
- In reply to: James Harris: "Re: Why in stdint.h have both least and fast integer types?"
- Next in thread: Flash Gordon: "Re: Why in stdint.h have both least and fast integer types?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 01 Dec 2004 19:07:34 GMT
In message <41ae0edd$0$1068$db0fefd9@news.zen.co.uk>
"James Harris" <no.email.please> wrote:
>
> "Kevin Bracey" <kevin.bracey@tematic.com> wrote in message
> news:cc6f86154d.kbracey@tematic.com...
> > The point you missed is that the _least types are supposed to be the
> > *smallest* types at least as wide, as opposed to the *fastest*, which are
> > designated by _fast.
>
> The *smallest* type as least as wide as 16 is of width 16, no? If it is
> impossible to support an integer of width 16 (18-bit word, for instance)
> how does the implementation deal with this standard's int16_t?
If an implementation doesn't have a 16-bit type, then int16_t isn't defined.
Its presence can be detected by #ifdef INT16_MAX.
int_least16_t and int_fast16_t have to be provided by all implementations,
int16_t only has to be provided if the implementation has 16-bit integers.
> I can see your point here. It's a subtlety. I still wonder, though, if I
> wouldn't prefer to specify that array as int16_t. Specifying int_least16_t
> is making me a hostage to the compiler. If I am taking in to account the
> architecture of the underlying machine (in this case, primary cache size)
> wouldn't I be better writing more precise requirements than int_leastX_t?
The only point is that, theoretically, using int16_t makes your code less
portable. The code wouldn't compile on a system lacking 16-bit types.
If you use int_least16_t, then that type *must* be 16-bit on any platform
with a 16-bit type. So you're not really a "hostage to the compiler" on
mainstream platforms.
But the advantage is that the code will also now compile on an odd platform
without 16-bit types. The code may still fail, if it can't actually cope with
a wider int_least16_t, but at least it will have made the attempt.
Use of int_fast16_t is more problematic - that's much more likely to be
wider than 16-bit on a mainstream platform, so you'll definitely have to code
carefully to make sure you're not relying on it only being 16-bit, if you
care about portability. But then, I suppose the same applies to any use of
int or long.
Personally, I've stuck to using int16_t instead of int_least16_t just to save
typing, and because I have no expectation of my code ever going near a system
without 8,16,32-bit types.
-- Kevin Bracey, Principal Software Engineer Tematic Ltd Tel: +44 (0) 1223 503464 182-190 Newmarket Road Fax: +44 (0) 1728 727430 Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
- Next message: Anand Hariharan: "Kernighan on Pascal (WAS Re: Learning C with Older books ?)"
- Previous message: Andrey Tarasevich: "Re: compiler won't allow dimensioned array of Char* to be signed to another???"
- In reply to: James Harris: "Re: Why in stdint.h have both least and fast integer types?"
- Next in thread: Flash Gordon: "Re: Why in stdint.h have both least and fast integer types?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]