Path: utzoo!attcan!uunet!mstan!amull From: amull@Morgan.COM (Andrew P. Mullhaupt) Newsgroups: comp.lang.c Subject: Re: () ignored in some expressions Summary: Kettle and pot both black Message-ID: <819@s6.Morgan.COM> Date: 11 Apr 90 14:54:38 GMT References: <48079@lanl.gov> <16414@haddock.ima.isc.com> <1990Apr10.181833.5453@utzoo.uucp> Organization: Morgan Stanley & Co. NY, NY Lines: 26 In article <1990Apr10.181833.5453@utzoo.uucp>, henry@utzoo.uucp (Henry Spencer) writes: > In article <1990Apr10.061333.29693@diku.dk> jensting@skinfaxe.diku.dk (Jens Tingleff) writes: > >Ahemm. Am I stupid, or is the result of 1000*(1000 - 999) quite dependant > >on the parenthesis being done properly (assume 16 bit int's..)? ... > > You're not stupid, just slightly careless. :-) You didn't read the original > query carefully enough -- only associative and commutative operators were > covered by the old rule, and subtraction is neither. Well what you say is true, but his example is still important when recast into the form: Big * (Big + x) where Big*Big overflows and Big + x is small enough. (x = 1-Big will work.) It is quite important to have this sorted out by compile time, since run time checks on all integer arithmetic are very expensive. Some compilers (especially FORTRAN) allow for a switch which can enable optimizations involving 'unsafe' code motion which might (if not used carefully) result in strange overflow behavior along these lines. Later, Andrew Mullhaupt