() ignored in some expressions

D. Richard Hipp drh at romeo.cs.duke.edu
Tue Apr 10 23:03:30 AEST 1990


>In MOST cases this [Ignoring ()]
>is not a problem with INTEGER math, but it is a BIG problem with
>floating point numbers.

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 probably notice that it can evaluate
3/2 at compile time to 1.  It will then notice that a multiplication by
1 can be ignored.  The end result is that my optimizing compiler will
decide not to generate any code at all for the above statement.

According to K&R, the only way to avoid this disaster is to code the
operation in two steps:   i *= 3; i /= 2;



More information about the Comp.lang.c mailing list