Q.4 Consider the following program fragment: foo(int x, int []) { int A[10], B[], *p, i; if (x > 3) B = C else B = A; fo

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Q.4 Consider the following program fragment: foo(int x, int []) { int A[10], B[], *p, i; if (x > 3) B = C else B = A; fo

Post by answerhappygod »

Q 4 Consider The Following Program Fragment Foo Int X Int Int A 10 B P I If X 3 B C Else B A Fo 1
Q 4 Consider The Following Program Fragment Foo Int X Int Int A 10 B P I If X 3 B C Else B A Fo 1 (138.55 KiB) Viewed 42 times
Keep in mind that in the C programming language: • there is
absolutely no difference between an array declaration int B[] and
int *B. They are identical in all respects. • a declaration like
int A[10] allocates space in memory of size 10 words (40 bytes)
pointed to by the 4-byte pointer A • in contrast, a declaration
like int B[] just declares an uninitialized pointer B of size 4
bytes, which does not point to any memory block at all. • the
memory space for an array argument like C is assumed to be
allocated by the caller function. (3 + 2 + 2 + 2 = 9 points) (a)
What are the alias classes in the above code? Recall that alias
classes are scalar variables whose address is taken, as well as
memory-allocated variables and memory blocks. (b) Given a
flow-sensitive alias analysis, what are the alias classes that are
in the points-to set of B[] immediately after the first for loop?
(The points-to set of a pointer at a program point are the set of
all alias classes that may-alias with that pointer at that program
point.) (c) Given a flow-sensitive alias analysis, what are the
alias classes that are in the points-to set of B[] immediately
after the second for loop? (d) Given a flow-insensitive alias
analysis, what are the alias classes that are in the points-to set
of B[] immediately before the only if statement ?
Q.4 Consider the following program fragment: foo(int x, int []) { int A[10], B[], *p, i; if (x > 3) B = C else B = A; for (i=0; i<10; i++) { B = i + 3; } B = malloc (sizeof(int) * 10); for (i=0; i<10; i++) { B = A + 4; } } + Keep in mind that in the programming language: there is absolutely no difference between an array declaration int B[] and int *B. They are identical in all respects. a declaration like int A[10] allocates space in memory of size 10 words (40 bytes) pointed to by the 4-byte pointer A in contrast, a declaration like int B[] just declares an uninitialized pointer B of size 4 bytes, which does not point to any memory block at all. • the memory space for an array argument like C is assumed to be allocated by the caller function. (3 + 2 + 2 + 2 = 9 points) (a) What are the alias classes in the above code? Recall that alias classes are scalar variables whose address is taken, as well as memory-allocated variables and memory blocks. (b) Given a flow-sensitive alias analysis, what are the alias classes that are in the points-to set of B[] immediately after the first for loop? (The points-to set of a pointer at a program point are the set of all alias classes that may-alias with that pointer at that program point.) (c) Given a flow-sensitive alias analysis, what are the alias classes that are in the points-to set of B[] immediately after the second for loop? (d) Given a flow-insensitive alias analysis, what are the alias classes that are in the points-to set of B[] immediately before the only if statement ?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply