Subject: Re: isspace and compiler warnings
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: David Laight <david@l8s.co.uk>
List: tech-userlevel
Date: 10/18/2006 21:15:30
On Wed, Oct 18, 2006 at 12:47:35PM -0400, der Mouse wrote:

> Yes.  But nothing says sizeof() units are octets.  I think some DSPs
> are word-addressed and use C with char, short, and int all one word (of
> 24? 32? bits) long.

Indeed the SHARC dsp can only address 32bit items and the C compiler
has sizeof (char) == sizeof (short) == sizeof (int) == sizeof (long) == 1.
Where all are 32 bits wide.

This shows up another fubar in the ansi C 'value preserving' integral
promotions (as opposed to the K&R 'signed preserving').

consider the following comparison:
    (unsigned char)a << 24 > (long)b
If sizeof char < sizof int < sizeof long, then 'a' is first promoted to
'signed int', shifted left some, then promoted to 'signed long' - which
can cause sign extension.
OTOH if sizeof (char) == sizof (int) then 'a' is promoted to 'unsigned int',
and the 2nd promotion will be to 'unsigned long' and any extra bits are zero.

	David

-- 
David Laight: david@l8s.co.uk