Path: utzoo!attcan!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: Detecting overflow Message-ID: <731@sdrc.UUCP> Date: 21 May 89 14:25:21 GMT References: <455@skye.ed.ac.uk> <723@tukki.jyu.fi> <1076@garcon.cso.uiuc.edu> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 21 In article <1076@garcon.cso.uiuc.edu>, mcdaniel@uicsrd.csrd.uiuc.edu (Tim McDaniel) writes: > Under pANS C, "(a*b)/b" cannot be optimized to "a". However, if it's not > pANS C-compliant, all bets are off. (That's the reason for having a > standard in the first place, so that at least SOME bets can be made. > :-) [where a and b are both integers] Sorry, but you're wrong -- pANS DOES allow the expression to be optimized provided the optimized expression gives the same result as the original expression in all cases where the result is well defined. If a and b are both integers, then the expression "a" does give the same result as "(a*b)/b" except when "(a*b)/b" overflows. If it overflows, the results are undefined and getting the "correct" answer without generating an overflow is certainly an allowable response to undefined behavior. ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@SDRC.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150-2789 AT&T: (513) 576-2070 "You can't get a body like mine in a bottle -- unless you push REAL HARD." - Judy Tenuta / Dr. Pepper