C optimizer

Jeffrey W Percival jwp at larry.UUCP
Tue Feb 14 02:23:20 AEST 1989


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 at larry.sal.wisc.edu)



More information about the Comp.lang.c mailing list