Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mit-eddie.UUCP Path: utzoo!linus!security!genrad!mit-eddie!smh From: smh@mit-eddie.UUCP (Steven M. Haflich) Newsgroups: net.lang.c Subject: Re: Must useless expressions be evaluated? Message-ID: <818@mit-eddie.UUCP> Date: Sat, 15-Oct-83 10:38:46 EDT Article-I.D.: mit-eddi.818 Posted: Sat Oct 15 10:38:46 1983 Date-Received: Sun, 16-Oct-83 11:26:37 EDT References: <187@bbncca.ARPA> Organization: MIT, Cambridge, MA Lines: 29 I am uneasy about any attempt to make a compiler smarter than a programmer, but can offhand think of only a couple situations in which it would not be safe to optimize out an unused computation. In particular, Unix autoconfiguration code can determine whether a device exists by peeking at one of its addresses. If a trap results, the device doesn't exist. How can a clever compiler determine whether an arbitrary reference might have an expected side effect of a trap? Some hardware provides for interrupt on certain data fetches, e.g., the little-used status bit in the PDP11 FPU which causes interrupt when -0 is fetched. The idea is that the hardware can detect reference to a variable before it is first set. (I don't know if Vaxen have a similar frob.) I could imagine situations where code might want to probe a variable using this hardware feature, throwing away the fetched value, in order that an interrupt not occur many levels deep in an evaluator. Lastly, a demand-paged program which wants to *attempt* real-time response to some input might try to touch the pages it expected to reference (e.g. some big array) to increase the probabilty they will be in physical memory when needed. Observe, of course, that all these examples involve explicit or implicit traps. C is, after all, a system programming languare, often likened to (ugh) assemble language, and one should be very careful about disturbing the clear mapping from C instructions into machine instructions. Steve Haflich MIT Experimental Music Studio