C optimizer

John Hascall hascall at atanasoff.cs.iastate.edu
Tue Feb 14 04:32:03 AEST 1989


In article <515 at larry.UUCP> jwp at 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



More information about the Comp.lang.c mailing list