PALLAS@SU-SCORE.ARPA (07/23/84)
From: "Joseph I. Pallas" <PALLAS@SU-SCORE.ARPA> Does anyone know if the ANSI standard will answer the burning question "Should signed values be sign-extended when cast into unsigned values?" PCC's insistence on doing this has caused more than a few bugs, although it is arguably correct, if frequently surprising. joe -------
jss@sfjec.UUCP (J.S.Schwarz) (07/27/84)
The paragraphs in section 3.2 of the latest version of the ANSI
Draft (dated July 11) dealing with conversions between signed and
unsigned follows:
"When a signed integer is combined with or assigned to an
unsigned integer of equal or greater length, the signed integer
is converted to unsigned and the result is unsigned. If the value
of the signed integer is negative, the conversion involves
adding to it the largest number that can be represented in the
unsigned integer plus one. In a twos-complement representation,
there is no actual change in the bit pattern except filling the
high-order bits with copies of the sign bit if the unsigned
integer is wider.
When an unsigned integer is converted to a longer signed integer
(for example, by assignment) its value is unchanged."
These paragraphs also govern conversion by casting.
Except that they don't cover conversions of unsigned to
equal or shorter types, they seem to be unambiguous.
This ambiguity is partialy covered by a sentence of paragraph 3.1
that says "When a longer integer is converted to a shorter integer
or to a char, it is truncated by discarding high-order bits."
Jerry Schwarz