quize1 - CPSC 213 Winter 2009 Term 2 Quiz 1 Solution Date...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CPSC 213, Winter 2009, Term 2 — Quiz 1 Solution Date: February 1, 2010; Instructor: Mike Feeley 1 When compiling code for reading a variable, what difference does it make to the compiler if the address of that variable is known dynamically or statically? Carefully explain. If the compiler knows the address (i.e., it is static) it can hardcode the address in the memory-read instruction. Other- wise, the compiler must generate code to compute the address at runtime, usually by reading it from memory. And thus variables with dynamic address usually require one additional memory read to access, compared to a similar variable with a static address. 2 Compare the following two pieces of C code to indicate what the compiler knows statically and what it doesn’t. Reading from a dynamic array. // declaration of global variables int * a, i; // reading from the array i = a[i]; Reading from a dynamically allocated struct. // declaration of global variables
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/11/2010 for the course CPSC cs213 taught by Professor Mikefeely during the Spring '10 term at UBC.

Ask a homework question - tutors are online