The following problem illustrates the way memory aliasing cancause unexpected program behavior. Consider the followingprocedure to swap two values:1 /* Swap value x at xp with value y at yp */2 void swap(long *xp, long *yp)3 {4 *xp = *xp + *yp; /* x+y */5 *yp = *xp - *yp; /* x+y-y = x */6 *xp = *xp - *yp; /* x+y-x = y */7 }If this procedure is called with xp equal to yp , what effect will ithave?A second optimization blocker is due to function calls. As an example,consider the following two procedures:1 long f();23 long func1() {4 return f ()+ f ()+ f ()+ f () ;5 }67 long func2() {8 return 4*f();9 }It might seem at first that both compute the same result, but withfunc2 calling f only once, whereas func1 calls it four times. It istempting to generate code in the style of func2 when given func1 asthe source.Consider, however, the following code for f:1 long counter = 0;23 long f() {4 return counter++;5 }This function has a side effect—it modifies some part of the globalprogram state. Changing the number of times it gets called changesthe program behavior. In

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The following problem illustrates the way memory aliasing can
cause unexpected program behavior. Consider the following
procedure to swap two values:
1 /* Swap value x at xp with value y at yp */
2 void swap(long *xp, long *yp)
3 {
4 *xp = *xp + *yp; /* x+y */
5 *yp = *xp - *yp; /* x+y-y = x */
6 *xp = *xp - *yp; /* x+y-x = y */
7 }
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 long f();
2
3 long func1() {
4 return f ()+ f ()+ f ()+ f () ;
5 }
6
7 long func2() {
8 return 4*f();
9 }
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
the source.
Consider, however, the following code for f:
1 long counter = 0;
2
3 long f() {
4 return counter++;
5 }
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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY