Unformatted text preview: y skip levels, and the depth may vary across the hierarchy. At the lowest level of the hierarchy there are leaf routines; these are routines which do not themselves call any lower-level routines. In a typical program some of the bottom-level routines will be library or system functions; these are predefined Program design Program hierarchy Leaf routines Figure 6.12 Typical hierarchical program structure. 176 Architectural Support for High-Level Languages operations which may or may not be leaf routines (that is, they may or may not have internal structure). Terminology There are several terms that are used to describe components of this program structure, often imprecisely. We shall attempt to apply terms as follows: Subroutine: a generic term for a routine that is called by a higher-level routine, particularly when viewing a program at the assembly language level. Function: a subroutine which returns a value through its name. A typical invoca tion looks like:
c = max (a, b); Procedure: a subroutine which is called to carry out some operation on specified data item(s). A typical invocation looks like:
printf ("Hello WorldXn"); C functions Some programming languages make a clear distinction between functions and procedures, but C does not. In C all subroutines are functions, but they can have side-effects in addition to returning a value, and when the returned value is of type 'void' it is effectively suppressed and only the side-effects remain, giving a behaviour which looks just like a procedure. An argument is an expression passed to a function call; a value received by the function is a parameter. C uses a strict 'call by value' semantics, so a copy is made of each argument when a function is called and, though the function may change the values of its parameters, since these are only copies of the arguments the arguments themselves are not affected. (A call by reference semantics would cause any change to a parameter within a function to be passed back to the calling program, which clearly only makes sense when the argument is a simple variable, but C does not support this.) The way a C function can change data within t...
View Full Document
- Spring '09