() ignored in some expressions

Andrew P. Mullhaupt amull at Morgan.COM
Thu Apr 12 00:54:38 AEST 1990


In article <1990Apr10.181833.5453 at utzoo.uucp>, henry at utzoo.uucp (Henry Spencer) writes:
> In article <1990Apr10.061333.29693 at diku.dk> jensting at 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



More information about the Comp.lang.c mailing list