Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!brl-adm!rutgers!ames!ucbcad!ucbvax!cartan!brahms!ballou From: ballou@brahms (Kenneth R. Ballou) Newsgroups: comp.lang.c,comp.std.internat Subject: Re: draft ANSI standard: one change that would *really* help Europe Message-ID: <559@cartan.Berkeley.EDU> Date: Sun, 14-Dec-86 22:35:20 EST Article-I.D.: cartan.559 Posted: Sun Dec 14 22:35:20 1986 Date-Received: Tue, 16-Dec-86 19:08:34 EST References: <1382@hoptoad.uucp> <8322@lll-crg.ARpA> <2221@eagle.ukc.ac.uk> <10429@sun.uucp> <518@brl-sem.ARPA> Sender: daemon@cartan.Berkeley.EDU Reply-To: ballou@brahms (Kenneth R. Ballou) Organization: Math Dept. UC Berkeley Lines: 38 Xref: mnetor comp.lang.c:399 comp.std.internat:50 In article <518@brl-sem.ARPA> ron@brl-sem.ARPA (Ron Natalie) 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@brahms Department of Mathematics UUCP: ...!ucbvax!brahms!ballou University of California Berkeley, California 94720 -------- Kenneth R. Ballou ARPA: ballou@brahms Department of Mathematics UUCP: ...!ucbvax!brahms!ballou University of California Berkeley, California 94720