Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!utfyzx!sq!msb From: msb@sq.UUCP Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: bug re unsigned to signed conversion? (side comment) Message-ID: <1987May29.122541.27690@sq.uucp> Date: Fri, 29-May-87 12:25:41 EDT Article-I.D.: sq.1987May29.122541.27690 Posted: Fri May 29 12:25:41 1987 Date-Received: Sat, 30-May-87 10:51:02 EDT References: <4626@columbia.UUCP> <4605@utah-cs.UUCP> Reply-To: msb@sq.UUCP (Mark Brader) Organization: SoftQuad Inc., Toronto Lines: 13 Xref: utgpu comp.lang.c++:264 comp.lang.c:2147 Checksum: 23942 Summary: (unsigned)-1 guaranteed == max unsigned Donn Seeley (donn@utah-cs.UUCP) writes: > ... on a two's complement machine, '(unsigned) -1' > is the largest unsigned integer. Actually, (unsigned) -1 should be the largest unsigned int on ANY machine. K&R Appendix A ref: section 6.5 on page 184 ANSI Oct.1 draft ref: section 3.2.1.2 on page 28 What IS true only on a 2's complement machine is that converting a negative number to unsigned does not change the bit pattern. Mark Brader, SoftQuad Inc., Toronto, utzoo!sq!msb #define MSB(type) (~(((unsigned type)-1)>>1))