IsUnsigned() function (retiring injured)

Chris Torek chris at mimsy.umd.edu
Thu Aug 2 15:46:49 AEST 1990


In article <621 at .tetrauk.UUCP> rick at .tetrauk.UUCP (Rick Jones) writes:
>Perhaps I finally understand the ANSII promotion rules at last!

Probably not. :-)  (Incidentally, `ANSI' has only one `I'; it is
`ASCII' that has two.)

Actually, the rule is fairly easy to state:  `In ANSI C, when an
unsigned type is promoted% to some other type, it becomes signed
(without changing value) if and only if the new type is actually
bigger.'  In practise, this means that you have to know whether
sizeof(short) < sizeof(int) and whether sizeof(char) < sizeof(int).

Alternatively, never let values promote without using a cast to
a non-promoting type; this avoids the problem entirely.
-----
% `Promotion' is not the same as `conversion' or `assignment'.
  See the standard (X3.159-1989) for an exact description.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list