Puzzle on unsigned promotions

s.hosgood iiit-sh at cybaswan.UUCP
Sat Jul 9 06:26:45 AEST 1988


Here at Swansea, we used to have an ancient C-compiler in the days
of V6 Un*x - in those days there was no unsigned' type, many people used to
use 'char *' as a kludge.

When K&R first came out it was in the 'documents with unix' distribution, but
on V7 it wasn't distributed as the authors decided to sell the book by then. I
presume they missed points like the sign-extension properties of 'unsigned'
during revision...

I found a similar problem to the above-mentioned occurs with assigning
constants. K&R don't really seem to specify if they consider a constant to
be signed or unsigned. However, they *do* seem to say that constants behave
like 'int's unless they are too long to be 'int', in which case they magically
become 'long'. I once actually had to write a compiler from scratch, and the
assignment:

	long	temp;

	temp = 0xFFFF;

..gave rise to the question of what to do? - treat the constant as an 'int'
of -1 and sign-extend, or treat it as an unsigned bit-pattern and just
zero-fill it? I chose the latter, but I never found a satisfactory answer
from K&R!



More information about the Comp.lang.c mailing list