0016 131072 5101 00031 262144 18671 00060 figure 58

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: +y-x = y */ If this procedure is called with xp equal to yp, what effect will it have? A second optimization blocker is due to function calls. As an example, consider the following two procedures: 1 2 3 4 5 6 7 8 9 10 11 int f(int); int func1(x) { return f(x) + f(x) + f(x) + f(x); } int func2(x) { return 4*f(x); } It might seem at first that both compute the same result, but with func2 calling f only once, whereas func1 calls it four times. It is tempting to generate code in the style of func2 when given func1 as source. Consider, however, the following code for f 1 2 3 4 5 6 7 int counter = 0; int f(int x) { return counter++; } This function has a side effect—it modifies some part of the global program state. Changing the number of times it gets called changes the program behavior. In particular, a call to func1 would return ¼ · ½ · ¾ · ¿ , whereas a call to func2 would return ¡ ¼ ¼, assuming both started with global variable counter set to 0. Most compilers do not try to determine whether a function is free of side effects and hence is a candidate for...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online