EXERCISES

  1. 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?
  2. Write a C program divided in two source files to demonstrate the effect of various scope and visibility rules of identifiers in C.
  3. Original BASIC language had only 26 variables named A to Z. How would have this limitation simplified the Symbol Table and Run-Time environment?
  4. 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?
  5. 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?
  6. 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.]
    1. Describe the basic structure of an Activation Record (AR).
    2. Where are ARs stored at run-time? Why?
    3. Why do you need an AR? What features of a language requires explicit AR and why?
    4. What are the purposes of the various access links? What language mechanism requires their use? Why?
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.101.81