Subject: Re: archive.c/arm32
To: Chris G. Demetriou <>
From: John F. Woods <>
List: current-users
Date: 03/23/1998 20:55:39
> > > 	((int)val & 0x100) == 0
> > > (if 'val' is signed and negative, it'll be sign-extended, so bits
> > > above the low 8 will be set.  otherwise those bits will be zero.)
> > If we were willing to require ANSI C,
> > 	(signed char)val >= 0
> No it wouldn't, because that would _force_ all chars to be signed,
> even if the implementation's chars are by default unsigned.

Doh!  I misunderstood the intent of the original expression.
In that case, I think that
	(int)val >= 0
does the right thing in every useful case:  if val is an unsigned type
strictly narrower than int, the result of casting to int will still be a
positive small integer; if val is a signed type strictly narrower than
int, then (int)val is negative if and only if val is negative.  Plus, it
doesn't misfire if char is wider than 8 bits (as if the code wrapped around
that line wouldn't!), and it more directly expresses the intent.

There are CPUs for which char is not narrower than int, but they're
special-purpose DSP chips, and not likely candidates for a NetBSD port.