Semi constant expressions

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Aug 31 10:34:47 AEST 1989


In article <1237 at gmdzi.UUCP> wittig at gmdzi.UUCP (Georg Wittig) writes:
>	0 * x			(x non-constant)
>	0 / x
>	x << (100000000L)
>	etc.
>Does (p)ANSI C say anything about which code should be generated for such
>expressions?

This falls naturally out of the specification.  The operands ARE evaluated,
so if `x' has side-effects they do occur.  If evaluation would produce what
the Standard labels as "undefined behavior", then the implementation can do
anything it likes including taking short cuts, but in cases where the
behavior is well defined the only short cuts permitted are those that
produce the same results as doing it the long way.

The Standard neither prohibits nor requires optimizations.  It prescribes
what the program behavior must be.



More information about the Comp.std.c mailing list