This preview shows page 1. Sign up to view the full content.
Unformatted text preview: so they assume that it might. For example, if vec length had some side effect, then combine1 and combine2 could have different behaviors. In cases such as these, the programmer must help the compiler by explicitly performing the code motion. As an extreme example of the loop inefﬁciency seen in combine1, consider the procedure lower1 shown in Figure 5.7. This procedure is styled after routines submitted by several students as part of a network programming project. Its purpose is to convert all of the upper-case letters in a string to lower case. The procedure steps through the string, converting each upper-case character to lower case. The library procedure strlen is called as part of the loop test of lower1. A simple version of strlen is also shown in Figure 5.7. Since strings in C are null-terminated character sequences, strlen must step through the sequence until it hits a null character. For a string of length Ò, strlen takes time proportional to Ò. Since strlen is called on each of the Ò iterations of lower1, the overall run time of lower1 is quadratic...
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.
- Spring '10
- The American