Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: C optimizer Keywords: C Ultrix Message-ID: <795@atanasoff.cs.iastate.edu> Date: 13 Feb 89 18:32:03 GMT References: <515@larry.UUCP> Reply-To: hascall@atanasoff.cs.iastate.edu (John Hascall) Organization: Iowa State U. Computer Science Department, Ames, IA Lines: 24 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? ... I think it will/should call the function each time it appears as the compiler has no way of knowing the "side-effects" of a function call (i.e., file operations, accessing global variables, etc). Imagine: x = (1 + printf(s)) / printf(s); y = printf(s) / (1 - printf(s)); (admittedly a hokey example--but you get the point...) John Hascall ISU Comp Center