unsigned char -> unsigned int conversion

keesan at bbncca.UUCP keesan at bbncca.UUCP
Wed Jun 13 00:20:27 AEST 1984


------------------------------

    haddock!lee says,

> Note that "char" is part of the sequence char-short-int-long, whereas
> "unsigned char" is part of the sequence uchar-ushort-uint-ulong, where the
> second sequence has the property "unsigned".  During coercions, unsigned
> chars are extended to unsigned whereas chars are extended to int (by zero
> extension or sign extension, whichever is appropriate).

    What are you using as a reference?  Clearly not Kernighan & Ritchie,
since unsigned chars weren't invented as of publication.  The only reference I
have to unsigned chars is "The C Programming Language" in the System V
"Programming Guide", and it doesn't allow unsigned short or unsigned long.
Is this a Berkeleyism?  What does the current draft ANSI standard say
about it?
    In upgrading our local C compiler to be System V compatible, I blithely
assumed that since our chars are unsigned, all I had to do was the syntactic
magic to make "unsigned char" equivalent to "char".  A careful reading of the
System V C manual leaves the question up in the air.  Their section on the
usual arithmetic conversions omits any mention of unsigned char (an obvious
oversight).  Would somebody with a Bell Labs System V C compiler try Lee's

    unsigned char foo=1; if( (-1|foo) > 0 ) printf("-1 is negative\n");

and report what it does?  Thanks.
-- 
					Morris M. Keesan
					{decvax,linus,wjh12,ima}!bbncca!keesan
					keesan @ BBN-UNIX.ARPA



More information about the Comp.unix.wizards mailing list