Semi constant expressions

Doug Gwyn gwyn at smoke.BRL.MIL
Wed Sep 6 02:45:04 AEST 1989


In article <242 at ssp1.idca.tds.philips.nl> dolf at idca.tds.PHILIPS.nl (Dolf Grunbauer) writes:
>In article <10885 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>>In article <1237 at gmdzi.UUCP> wittig at gmdzi.UUCP (Georg Wittig) writes:
>>>	0 * x			(x non-constant)
>>>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.
>How can you tell what will happen when 'doing it the long way' ?

I thought this was clear from what I said and from the context.  In the
case
	0 * x
if evaluation of the expression `x' would have observable side effects
then they MUST occur for a correct implementation of C.  In such a case,
an implementation that replaced the expression "0 * x" with the constant
"0" as an "optimization" would not be standard conforming.

The run-time behavior of a C program is defined in terms of the operation
of a "virtual machine" (with some deliberately fuzzy areas in its
specification, so it's really a class of virtual machines) and input/output
operations (which are usually what makes the program's behavior observable).
A correct implementation must produce observable results identical to those
that would be produced by the virtual machine (actually, by some member of
the class of virtual machines).



More information about the Comp.std.c mailing list