Semi constant expressions

Georg Wittig wittig at gmdzi.UUCP
Thu Aug 31 01:10:32 AEST 1989


I haven't seen this topic in comp.lang.c and comp.std.c in the last months ...
 
My question is about semi constant expressions, i.e. about expressions of the
form
	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? K&R I and Harbison&Steele II don't seem to cover this. Does ANSI
C? (I don't have the ANSI C papers, so please `cat flames > /dev/null`)

Three possibilities come to my mind, how code can be generated for those
expressions:

1)	Compilers are free to generate code as if the constant expression `0'
	had been seen, even if `x' can have side effects (`x' could be a
	function call `foo()').

2)	If `x' has no side effects, prentending a constant expression `0'
	might be o.k.; however if `x' can have side effects, compilers should
	interpret `0 * foo()' as if they had seen `(foo(), 0)'.

3)	Compilers must not think about such binary expressions and must
	always generate code for multiplication, division. etc.

H&S II p. 162: "both operands are fully evaluated (but in no particular order)
before the operation is performed." However, nothing is said about optimization
in those semi constant expressions. Nevertheless, that sentence seems to imply
that case 3 above (and may be case 2 also) is the correct solution. Is ANSI C
more specific at these cases?

BTW:
- How about `int x,y; x=0; y=x*foo()' thrown to a good optimizing compiler?
  What is it allowed to optimize away?

- Does there exist an offical word for what I called `semi constant
  expression'?


-- 
Georg Wittig		     email:wittig at gmdzi.uucp   phone:(+49 2241) 14-2294
German National Research Laboratory for Computer Science (GMD)
P.O. Box 1240				|"Freedom's just another word for noth-
D-5205 St. Augustin 1 (West Germany)	| ing left to lose" (K. Kristofferson)



More information about the Comp.std.c mailing list