short circuit evaluation

john at viper.UUCP john at viper.UUCP
Fri Feb 13 08:59:24 AEST 1987


I agree totaly with Dan Hoey's statement on this subject.  There is -FAR-
too much code already existing which requires non-shortcircuit evaluation
of '|' and '&' operations.  Since one of the primary considerations that
has been stated by the standards committee was to avoid "breaking" as much
existing software as possible, and since, as Dan pointed out, "a standard
which is silent on this point is no standard", it seems that at very least
all side effects -must- be carried out.  As long as the code produces the
same results, I doubt any of us will object if the compiler creates some
bizarre method of getting things done in the least amount of time.
  What this means to me is that code written in optimized C, where side
effects are known and taken into account, won't break just because some
tight loop got short circuited and an increment got skipped.  This kind
of code exists -everywhere-.  If we allow side effects like increment
or function calls to be skipped in one "optimized" compiler and not in
the standard run-of-the-mill type complers that most of us use, the standard
itself will have introduced portability problems by an omission...
  If the compiler people want to create code which stops evaluating the
results after a fixed result is known, I say fine.  BUT, they must take
the responsibilty of picking up the peices and making sure the incidental
increments,etc are taken care of!



More information about the Comp.lang.c mailing list