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!barmar From: barmar@mit-eddie.UUCP (Barry Margolin) Newsgroups: net.lang.c Subject: Re: Re: Must useless expressions be evaluated? Message-ID: <821@mit-eddie.UUCP> Date: Tue, 18-Oct-83 00:25:55 EDT Article-I.D.: mit-eddi.821 Posted: Tue Oct 18 00:25:55 1983 Date-Received: Tue, 18-Oct-83 22:46:01 EDT References: <337@wjh12.UUCP> Organization: MIT, Cambridge, MA Lines: 22 Yes, Steve Haflich has a point about special locations which have side-effects just from being accessed. However, there are plenty of ways to fool a compiler into leaving the references around without giving up a very common optimization. For instance, you could have a library routine, do_nothing, which takes one argument and just returns. You could then say "do_nothing(*special_loc)". The compiler has no way of knowing that the parameter will be ignored, and I have never heard of an optimizing loader (at least not that smart). It is not too smart to depend too heavily on what you expect the generated code to be. For instance, *special_loc+*special_loc will probably NOT access special_loc twice; more likely, it will be loaded into a register, and doubled. A good optimizer can really contort your code in order to generate efficient code. Perhaps there should be ways to tell the compiler and optimizer that certain variables should never be optimized into registers (a not_register declaration?). Another place to be careful is in expressions; I believe that C does not define the order of evaluation of terms in an expression (I know PL/I doesn't). -- Barry Margolin ARPA: barmar@MIT-Multics UUCP: ..!genrad!mit-eddie!barmar