Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!nic.MR.NET!indri!larry!jwp From: jwp@larry.UUCP (Jeffrey W Percival) Newsgroups: comp.lang.c Subject: C optimizer Keywords: C Ultrix Message-ID: <515@larry.UUCP> Date: 13 Feb 89 16:23:20 GMT Organization: UW-Madison Space Astronomy Lab Lines: 19 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? Specifically, I am using ULTRIX 2.1 on a VS2000, but my real question is, would *most* compilers optimize this as I'd hope, or *some* compilers, or hardly any? I guess I'm looking for a gut feeling on the general situation rather than in this specific example. If a function is used several times in a routine with an argument that doesn't get assigned to, is the result generally stashed somewhere? And what are the types of operations that interfere with an ongoing optimization, causing calls to be re-made rather than pulled from some stash? -- Jeff Percival (jwp@larry.sal.wisc.edu)