() ignored in some expressions

Karl Heuer karl at haddock.ima.isc.com
Wed Apr 11 04:56:48 AEST 1990

In article <18833 at duke.cs.duke.edu> drh at duke.cs.edu writes:
>I often what to do things like increase an integer by 50%.  This can
>be done as follows:    i = (i*3)/2;   If an optimizing compiler can
>ignore the parenthesis, then it will [reduce this to a no-op]

Yeah, right.  And it will change "(x+1)*(x+1)" to "x + 1*x + 1", which isn't
what I wanted!  Horrors!

Seriously, folks, this is *not* what K&R 1 said.  "i = (i*3)/2" has always
been safe from this type of optimization.

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint

More information about the Comp.lang.c mailing list