draft ANSI standard: one change that would *really* help Europe
Kenneth R. Ballou
ballou at brahms
Mon Dec 15 13:35:20 AEST 1986
In article <518 at brl-sem.ARPA> ron at brl-sem.ARPA (Ron Natalie <ron>) writes:
> ... nowhere is it stated that (unsigned) -1 will give you a word of
>all ones. Becareful when making this assumption. I spend a lot of time
>fixing up the Berkeley network code because of this.
Actually, I think (unsigned) -1 does have to give you a bit pattern of
all 1's. I can not find an explicit reason, but I can deduce this from the
following:
1. Harbison and Steele, page 89:
"No matter what representation is used for signed integers,
an unsigned integer represented with n bits is always considered to
be in straight unsigned binary notation, with values ranging from
0 through 2^n-1. Therefore, the bit pattern for a given unsigned
value is predictable and portable, whereas the bit pattern for a
given signed value is not predictable and not portable."
2. Harbison and Steele, pages 126-7 (talking about casting an integral
type into an unsigned integral type):
" If the result type is an unsigned type, then the result
must be that unique alue of the result type that is equal (congruent)
mod 2^n in the original value, where n is equal to the number of bits
used in the representation of the result type."
3. The value in the range 0 to 2^n-1 (inclusive) congruent mod 2^n
to -1 is 2^n-1. In straight binary notation this value is repre-
sented as all 1's.
--------
Kenneth R. Ballou ARPA: ballou at brahms
Department of Mathematics UUCP: ...!ucbvax!brahms!ballou
University of California
Berkeley, California 94720
--------
Kenneth R. Ballou ARPA: ballou at brahms
Department of Mathematics UUCP: ...!ucbvax!brahms!ballou
University of California
Berkeley, California 94720
More information about the Comp.lang.c
mailing list