() ignored in some expressions

Henry Spencer henry at utzoo.uucp
Sun Apr 15 09:54:32 AEST 1990


In article <819 at s6.Morgan.COM> amull at Morgan.COM (Andrew P. Mullhaupt) writes:
>> ... 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)

The "*" operator neither associates nor commutes with "+", so this is
*still* irrelevant to the discussion at hand.  Some compilers will try
to use the *distributive* property to optimize this expression, but that
has always been an optimization that would -- if integer overflow produces
noticeable effects, rare in old compilers -- break the rules.  There has
never been a rule allowing the compiler to use distributivity in the way
that use of associativity and commutativity was explicitly allowed.

>It is quite important to have this sorted out by compile time, since
>run time checks on all integer arithmetic are very expensive. 

This depends on the machine and the compiler.  On some it's essentially
free.
-- 
With features like this,      |     Henry Spencer at U of Toronto Zoology
who needs bugs?               | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list