asctime.c

Clive D.W. Feather clive at demon.net
Mon Aug 2 07:48:58 UTC 2004


Andrew Brown said:
>>>> K&R isn't the Standard, and sometimes simplifies.
>>> true, but the second edition has the ansi stamp on it, and afaik
>>> there's no third edition.
>> The "ansi stamp" simply means that they made changes to match C99.

Argh. That should have said "C90".

>> Actually it was. Significantly - you're looking at the person who wrote the
>> new text.
>> [Before you panic, the basic concepts are unchanged, but a whole load of
>> subtle issues have now been addressed.]
> of the five i noted, have any of them changed at all?

Let's see:

>     + short and long are intended (but not required) to be different
>       lengths

The Standard tries to avoid "intended". short and long can be the same
length or different lengths.
   
>     + int will be the "natural size" for a machine

"A ``plain'' int object has the natural size suggested by the
architecture of the execution environment"

>     + shorts and ints are at least 16 bits
>     + longs are at least 32 bits

These limits are defined in terms of the minimum range of values rather
than bit counts. This is because types can have bits that don't take part
in calculations; for example, a 16 bit storage unit might only have 12 bits
that take part in calculations.

signed short and signed int must be able to hold -32767 to +32767.
unsigned short and unsigned int must be able to hold 0 to 65535.
signed long must be able to hold -2147483647 to +2147483647.
unsigned long must be able to hold 0 to 4294967295.

>     + sizeof(short) <= sizeof(int) <= sizeof(long)

This one has gone. The requirements are:

    sizeof(signed short) == sizeof(unsigned short)
    sizeof(signed int)   == sizeof(unsigned int)
    sizeof(signed long)  == sizeof(unsigned long)

    USHRT_MAX >= SHRT_MAX
    UINT_MAX  >= INT_MAX
    ULONG_MAX >= LONG_MAX

    SHRT_MAX  <= INT_MAX
    USHRT_MAX <= UINT_MAX
    INT_MAX   <= LONG_MAX
    UINT_MAX  <= ULONG_MAX

This does allow a perverse implementation where long is 32 bits, all used,
while short is 64 bits but only 17 of them are used. There are reasons (too
off-topic to go into) why we did it this way.

> therefore, int could be 128 bits if you liked, but long would have to
> be at least as many, while short could only be at most as many.  and
> that's it.

See above.

-- 
Clive D.W. Feather  | Work:  <clive at demon.net>   | Tel:    +44 20 8495 6138
Internet Expert     | Home:  <clive at davros.org>  | Fax:    +44 870 051 9937
Demon Internet      | WWW: http://www.davros.org | Mobile: +44 7973 377646
Thus plc            |                            |



More information about the tz mailing list