Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!dciem!nrcaer!cognos!jimp From: jimp@cognos.uucp (Jim Patterson) Newsgroups: comp.lang.c Subject: Re: Optimization vs. the programmer Message-ID: <541@cognos.uucp> Date: Fri, 10-Apr-87 12:53:14 EST Article-I.D.: cognos.541 Posted: Fri Apr 10 12:53:14 1987 Date-Received: Sat, 11-Apr-87 18:46:29 EST References: <479@danews.ATT.COM> Reply-To: jimp@cognos.UUCP (Jim Patterson) Organization: Cognos Incorporated, Ottawa, Canada Lines: 38 In article <479@danews.ATT.COM> lvc@danews.UUCP writes: >There is a certain computer (that I still use) that >requires the statement: > > n = n; > >in order to force the hardware to work right for certain >values of n. >If I had an optimizing compiler that was smart (?$!?) >enough to excise this I couldn't make the machine work >right. I suggest that the compiler should do more - it should perform its calculations so that the necessary operations (e.g. "n = n") are done automatically, as necessary, to ensure that the results are correct. If I am porting software to this certain computer, I certainly would not want to go into the code and insert dummy assignments wherever necessary (wherever that is) just to make otherwise valid algorithms work. This is a task that the compiler should do for me. Otherwise, it is not correctly implementing the abstract machine model for the C language. Conversely, if I am using a machine where these dummy assignments aren't necessary, then I don't care if the compiler removes them except that in general I want the code to run as fast as possible, but correctly of course. C is a (reasonably) portable language for sofware development. As such, it depends on an abstract machine model to define its operations. The role of any C compiler is to implement that model as closely as is possible. To this end, it should not do any optimizations that comprimise its conformance to the model. Hence, on your computer it should not likely optimize out "n = n" if it may affect the results of an operation (unless it otherwise guarantees that "n" is properly represented, which I think is the preferrable approach). Conversely, any optimizations it can do which DO NOT ALTER the results that are predicted by the abstract model can reasonably be performed.