Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!topaz.rutgers.edu!ron From: ron@topaz.rutgers.edu (Ron Natalie) Newsgroups: comp.lang.c Subject: Re: Expressions compared to zero in *c* Message-ID: <14556@topaz.rutgers.edu> Date: Tue, 8-Sep-87 21:00:02 EDT Article-I.D.: topaz.14556 Posted: Tue Sep 8 21:00:02 1987 Date-Received: Thu, 10-Sep-87 01:24:48 EDT References: <374@mcdsun.UUCP> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 29 > Does (a-b) < 0 imply a < b ? Pick a and b for controversy. NO. Not if you overflow the value, the calculations are invalid. For example. Define MAXINT to be the largest positive number representable by type int. The expression MAXINT+1 will on most machines be the largest negative number. Do you insist that it compare ">" 0 ? Even if the compiler had the hope of knowing that ( a - b ) caused an overflow that is checkable by the adjacent > operator, you've destroyed that with the cast in your example program. A cast has exactly the same effect as assigning a value to a variable of the type of the cast and then referencing that variable That is TYPEA x; TYPEB y; ((TYPEB) x) is equivelent to (y = x) only without the need for the intermediate "y" value. Hence (CAST) (a-b) becomes a positive number by virtue of being stored, (CAST) (MAXINT+1) becomes negative by virtue of being stored. C doesn't keep overflow bits in the stored variables. Overflowing variables (unless you know what will happen) is an error. This is an EXCEPTION. You either have to check this carefully or hope you have hardware that is going to notify you of the error.