Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!ima!haddock!karl From: karl@haddock.UUCP Newsgroups: comp.lang.c Subject: (unsigned)-1 (Was: draft ANSI standard: one change that would Message-ID: <200@haddock.UUCP> Date: Mon, 15-Dec-86 21:19:36 EST Article-I.D.: haddock.200 Posted: Mon Dec 15 21:19:36 1986 Date-Received: Wed, 17-Dec-86 05:38:47 EST References: <1382@hoptoad.uucp> <8322@lll-crg.ARpA> <2221@eagle.ukc.ac.uk> <10429@sun.uucp> <518@brl-sem.ARPA> Reply-To: karl@haddock.ISC.COM.UUCP (Karl Heuer) Organization: Interactive Systems, Boston Lines: 21 In article <518@brl-sem.ARPA> ron@brl-sem.ARPA (Ron Natalie) writes: >Second, 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. I presume you're thinking of one's complement machines, where the internal representation of (int)-1 does not have all bits set. However, as stated in K&R (Appendix A, Section 6.5), "The value [after converting a signed integer to an unsigned] is the least unsigned integer congruent to the signed integer (modulo 2**wordsize)." Thus, on a 16-bit machine (unsigned)-1 denotes 65535, which does indeed have all bits set. Moreover, the same paragraph states that "in a two's complement representation, this conversion is conceptual and there is no actual change in the bit pattern"; the inclusion of that first phrase suggests that the conclusion is not valid in other representations. (X3J11 uses similar language, I believe.) I've never used C on non-two's-complement machines -- do they obey this? Of course, the *correct* way to get a word full of ones is "~(unsigned)0". Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint