unsigned char -> unsigned int co - (nf)

jim at ism780.UUCP jim at ism780.UUCP
Thu Jun 21 14:12:43 AEST 1984


#R:bbncca:-77800:ism780:14400013:000:2496
ism780!jim    Jun 12 22:36:00 1984

>     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?

Kernighan & Ritchie is obsolete.  AT&T documentation often lags behind the
code for a release or two, so it can't be counted on either.  According to the
System V Release 2 C Language document,

"
basic-type-specifier:
	basic-type
	basic-type basic-type-specifiers
basic-type:
	char
	short
	int
	long
	unsigned
	float
	double
	void

At most one of the words long or short may be specified in conjunction with
int; the meaning is the same as if int were not mentioned.  The word long
may be specified in conjunction with float; the meaning is the same as double.
The word unsigned may be specified alone, or in conjunction with int or any of
its short or long varieties, or with char.

Otherwise, at most on [sic] type-specifier may be given in a declaration.
In particular, adjectival use of long, short, or unsigned is not permitted
with typedef names.  If the type-specifier is missing from a declaration,
it is taken to be int.
"

I think the text pretty clearly describes what the modern compilers
[are intended to] allow; it certainly beats the idiotic and obsolete listing
of specific cases in previous documents. The syntax specification is of course
as useless as ever.

>     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.

The only way the question could be left in the air is if it were reasonable
to promote unsigned char to int instead of unsigned int; this would obviously
be idiotic, and fortunately the SysV.2 doc agrees:

"... any operands of type unsigned char or unsigned short are converted to
unsigned int".

-- Jim Balter, INTERACTIVE Systems (ima!jim)



More information about the Comp.unix.wizards mailing list