Give a layout of the Activation Record for the legacy C compiler function calling conventions discussed in Section 7.1.2. Compare it with the theoretical Activation Record layout. Is there a static links area in this AR? Why? Is it possible to access identifier in the outer block? If yes, how can that be arranged?
Write a C program divided in two source files to demonstrate the effect of various scope and visibility rules of identifiers in C.
Original BASIC language had only 26 variables named A to Z. How would have this limitation simplified the Symbol Table and Run-Time environment?
A student wrote the following code to print values of elements of an array a:
int a[100];
int main(){
int n;
// compute the array a[]
n = 0;
while(n < 100)
printf(″a[%d] = %d
″, n, a[n++]);
}
What is wrong with this code, if anything?
In C, if a large-sized data structure like an array or a struct is to be passed as an argument to a function, generally a pointer to that item is passed. This opens up a possibility for the called function inadvertently modifying the values within the argument data structure. Is it possible to protect against such occurrence? How can you prevent this?
Laboratory exercise: Write simple C programs containing individually IF-THEN, IF-THEN-ELSE, WHILE-DO, DO-WHILE, SWITCH-CASE statements, struct definitions and array manipulation operations. Compile them to obtain the assembly language output. Prepare a note on how each control construct and data aggregation get translated. [Hint: Use gcc –c –S –o myprog.S myprog.c to get assembly output.]
Describe the basic structure of an Activation Record (AR).
Where are ARs stored at run-time? Why?
Why do you need an AR? What features of a language requires explicit AR and why?
What are the purposes of the various access links? What language mechanism requires their use? Why?