Signed Characters

rbj%icst-cmr at smoke.UUCP rbj%icst-cmr at smoke.UUCP
Thu Apr 17 00:24:58 AEST 1986


> > 	Consider the following problem.  You have an array of 4 byte
> > integers.  If you sort the array numerically you get one result.  If
> > you regard the bytes as characters and sort them lexicographically on
> > a little endian machine you get a different result.  The reason is that
> > the most signifigant byte occupies the eight least signifigant bits.
> > Consistency of signifigance requires that the direction of signifigance
> > be the same for both bytes and bits.
> 
> If your machine has unsigned characters and two's-complement integers with
> the sign bit in the high bit -- e.g. 360/370 -- then neither byte order
> will make the two comparisons come out the same.  So quite apart from all
> the other flaws in this argument, it just doesn't work.
 
> Before you start defending signed characters, remember that they were
> another arbitrary invention of the pdp11.  And a mistake, too.
> -- 
> 				Henry Spencer @ U of Toronto Zoology
> 				{allegra,ihnp4,decvax,pyramid}!utzoo!henry
 
Well, the PDP had some trouble cramming all it's instruxions into those
sixteen bit words. Left out was byte arithmetic. I think we all agree
that both signed and unsigned operations are desirable on all integer sizes.
Bytes not only hold chars, but also small integers.

If restricted to only one flavor, I would choose signed any day. 
It it easier on a PDP-11 to mask the high byte if unwanted than to
generate it (sign extend) if needed.

	(Root Boy) Jim Cottrell		<rbj at cmr>



More information about the Comp.lang.c mailing list