Int and Char

Guy Harris guy at sun.uucp
Sun Jul 27 15:20:58 AEST 1986


> I agree this is a major oversight in portability, but I think the main
> reason that there is no 'signed' adjective for chars is that the
> representation and interpretation for chars is too machine dependent.

The trouble with this theory is that there *is* a "signed" adjective for
"char"s in ANSI C; somebody recently claimed here that some C compiler even
implemented it.

> That is, a machine can not be told to interpret chars as signed if it only
> knows about unsigned reprsentations.

Oh, yes it can!  It may not be *convenient*, but it's certainly *possible*.
Consider the sequence

	load byte into register
	if (high-order bit of that byte == 1)
		OR in a mask of 1's to set all bits above it

You now have that "char" in the register, sign-extended.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.lang.c mailing list