In message: <[EMAIL PROTECTED]> Jeff Roberson <[EMAIL PROTECTED]> writes: : : On Sat, 17 Mar 2007, Max Laier wrote: : : > On Saturday 17 March 2007 20:09, Jeff Roberson wrote: : >> Any language lawyers care to comment on this? : > : > I find this strange. According to the spec "(Decrementing is equivalent : > to subtracting 1.)", but "pri = --pri % RQ_NQS;" will behave like you : > expect, while "pri = (pri - 1) % RQ_NQS;" clearly didn't. : : I noticed this as well. : : When you do --pri, pri is promoted to int for the math and then demoted : back to char wich truncates the value. Subsequently this value is used : in the % operation, which gives the expected results. : : When you do pri - 1 the intermediate result is promoted to a signed int : which doesn't yield the result you'd like when you mod with 64.
(pri - 1u) % 64 is likely what you want. That way the (pri - 1u) turns out to be unsigned because it is (unsigned - unsigned) % signed. which winds up being unsigned % signed. The - 1 version is (unsigned - signed) % signed, which breaks down to signed % signed, which yields the strange result that you saw. (unsigned char)(pri - 1) % 64 is another way to fry this fish. Warner _______________________________________________ cvs-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/cvs-all To unsubscribe, send any mail to "[EMAIL PROTECTED]"