Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!purdue!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.lang.c Subject: Re: C optimizer Keywords: C Ultrix Message-ID: <12197@dartvax.Dartmouth.EDU> Date: 13 Feb 89 18:06:07 GMT References: <515@larry.UUCP> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Organization: Thayer School of Engineering Lines: 19 In article <515@larry.UUCP> jwp@larry.UUCP (Jeffrey W Percival) writes: >I have a question about how much optimizing I should worry about when >writing programs in C. Suppose I have this code fragment: > > x = (1 + cos(r)) / (cos(r) * sin(r)); > y = (cos(r) - sin(r)) / (1 + sin(r)); > >I made this up, but the point is the re-use of the sin() and cos() >calls. Now, can I expect the compiler to form only one call to sin and >cos? No. The compiler has no way of knowing what sin() and cos() do, besides obviously returning a result. Either or both might have side effects, and optimizing out any of the calls prevents the side effects from happening. Earle R. Horton. 23 Fletcher Circle, Hanover, NH 03755--Graduate student. He who puts his hand to the plow and looks back is not fit for the kingdom of winners. In any case, 'BACK' doesn't work.