Re: Why in stdint.h have both least and fast integer types?

From: Flash Gordon (spam_at_flash-gordon.me.uk)
Date: 12/01/04


Date: Wed, 1 Dec 2004 22:08:08 +0000

On Wed, 1 Dec 2004 18:35:19 -0000
"James Harris" <no.email.please> wrote:

> "Kevin Bracey" <kevin.bracey@tematic.com> wrote in message
> news:cc6f86154d.kbracey@tematic.com...
> > In message <79062cd3.0411270240.29d3a4f7@posting.google.com>
> > groupstudy2001@yahoo.co.uk (GS) wrote:
> >
> >> The stdint.h header definition mentions five integer categories,
> >>
> >> 1) exact width, eg., int32_t
> >> 2) at least as wide as, eg., int_least32_t
> >> 3) as fast as possible but at least as wide as, eg., int_fast32_t
> >> 4) integer capable of holding a pointer, intptr_t
> >> 5) widest integer in the implementation, intmax_t
> >>
> >> Is there a valid motivation for having both int_least and int_fast?
> >
> > 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?

Only on implementations *having* a type that is exactly 16 bits wide.

> 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?

That's simple. It does not define int16_t

> > A typical example might be the ARM, which (until ARMv4) had no
> > 16-bit memory
> > access instructions, and still has only 32-bit registers and
> > arithmetic instructions. There int_least16_t would be 16-bit, but
> > int_fast16_t might be
> > 32-bit.
> >
> > How you decide what's "fastest" is the tricky bit.
>
> Absolutely! There is no point making a data type "fast" if it is to be
> repeatedly compared with values which are not the same width. Of
> course, operations are fast or slow, not data values. Is the standard
> confusing two orthogonal issues?

There are generally speed issues which are related to size, such as a
system with a 32 bit address bus that can quickly access a 32 bit type
but has to either mask or shift the data to access a 16 bit value.

<snip>

> 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?

Well, when you port the SW to a 32 bit DSP processor that has absolutely
no support for 16 bit data and therefor does not provide int16_t? Such
an implementation can easily provide both int_least16_t and
int_fast16_t, anthough they would both be identical to int32_t

-- 
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


Relevant Pages

  • Re: Buffer overflows and asctime()
    ... struct tm members to be within their valid ranges is up to an user of ... There is no valid range for the year as specified in the standard. ... I wouldn't call it a defect, because the existence of a limit beyond which asctime() cannot be safely used is inferable from the description of asctime. ... I would consider it a substantial improvement for the standard to explicitly specify the limit. ...
    (comp.std.c)
  • Re: [fitsbits] Comments on image distortion conventions
    ... The document should specify default values for any coefficients that are absent from the header, but might be expected based upon the value of A_ORDER or B_ORDER. ... Presumably either the values would be taken to be zero or the convention should require that all keywords be present. ... The convention would appear to mis-use the CTYPEi reserved keyword in a way that at least technically violates the FITS standard. ... of including distortion in the pixel world coordinate transformation directly. ...
    (sci.astro.fits)
  • Re: Boolean Buyers Beware ... AIX compiler bug --- PMR 26241,756
    ... But the compiler does have other options for updating byte fields, ... I didn't bring the C++ standard into the discussion, ... C++ doesn't specify anything here, and still one needs multithreading. ...
    (comp.programming.threads)
  • Re: Boolean Buyers Beware ... AIX compiler bug --- PMR 26241,756
    ... IBM identified a source work-around, and claimed the problem was our ... I don't think the C++ standard has a word to say about threads. ... C++ doesn't specify anything here, and still one needs multithreading. ...
    (comp.programming.threads)
  • Meaning of implementation def. behaviour (was: Re: C99 IDE for windows)
    ... International Standard provides two or more possibilities and imposes ... provides all possible courses of action and the implementation is ... how can the Standard specify the output ...
    (comp.lang.c)