🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #510

Semi constant expressions

#510
From: Georg Wittig
Date: Wed, 30 Aug 1989 15:10
47 lines
2287 bytes
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@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)
Technical Details
Message-ID: <1237@gmdzi.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!dptg!rutgers!cs.utexas.edu!uunet!mcsun!unido!gmdzi!wittig

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!dptg!rutgers!cs.utexas.edu!uunet!mcsun!unido!gmdzi!wittig
From: wittig@gmdzi.UUCP (Georg Wittig)
Newsgroups: comp.std.c
Subject: Semi constant expressions
Keywords: expressions, optimization, code generation
Message-ID: <1237@gmdzi.UUCP>
Date: 30 Aug 89 15:10:32 GMT
Organization: GMD - Gesellschaft fuer Mathematik und Datenverarbeitung mbH
Lines: 47