Functionality ◾ 69
address, and stores the value of the program counter at the point of call (so
that the function return can execute correctly). Functions may have local
data: the compiler lays out memory for such data. Statement #1 in each
function in Example 3.7 illustrates the allocation of local data (the pointer
db) as does the passed parameter n in Example 3.14. e program counter
and local data are laid out in a stack frame associated with the function.
Example 3.7: Premature vs. Timely Return: C++
//return may be executed before resource released => memory leak
void misManagedResources()
{ int* db = new int[100]; //#1 resource (memory) allocated
if (done()) return; //#2 avoid work if not needed
//resource not released ...