Concepts of Programming Languages
Chapter 9 – Subprograms – Review
What are the 3 general characteristics of subprograms?
Each subprogram has a single entry end points – the calling program unit is suspended during
the execution of the called subprogram, which implies that there is only one subprogram in
execution at any given time – control always return to the caller when the subprogram execution
What does it means for a subprogram to be active?
It means that after the subprogram have been called, it has begun execution but hasn’t yet
completed that execution
What is given in the header of a subprogram?
Type a special words
What is a parameter profile? What is subprogram protocol?
 Parameter profile of a subprogram contains the number, order, and types of its forms
 A protocol of subprogram is its parameter profile plus, if it is a function, its return type
What are formal parameters? What are actual parameter?
 A Formal parameter is the parameter in the subprogram header. They are sometimes
thought of as dummy variables because they are not variable in the usual case.
 An Actual parameter is a subprogram call statement that must include the name of the
subprogram and a list of parameters to be bound to the formal parameter of the
What are the differences between a function and a procedure?
A function returns value but procedures do not. Function are structurally resemble procedures
but are semantically modeled on mathematical parameter.
What are the design issues of a subprogram?
 Are local variable statically or dynamically allocated?
 Can subprogram definitions appear in other subprogram definition?
 What parameter-passing method or methods are used?
 Can subprogram overload?
 Can subprogram be generic?
 If a language allow nested subprogram, are closures supported?
What are the advantages and disadvantages of dynamic local variable?
Advantage they are bound to storage when the subprogram begins execution and
are unbound from storage when that execution terminates – flexible –
the storage for local variables in an active subprogram can be shared
with the local variable in all inactive subprogram.
Disadvantage the cost of time required to allocate, initialize, and deallocate such
variables for each call to the subprogram. – the access to stackdynamically local variable must be indirect. – subprogram cannot be
history sensitive.
What languages allow subprogram definitions to be nested?
 Algol 60
 Algol 68
 Pascal
 Ada
What are the three semantic models of parameter passing?
In mode receive data from the corresponding actual parameter
Out mode transmit data to the actual parameter
InOut mode can do both
What is the parameter-passing method that Python and Ruby?
It is called passed by assignment
Which restriction are called bounds?
Generic parameter must be classes (cannot be primitive), although generic method can be
instantiated any number of times only one copy of the code is built, the range of classes that can
be passed to the generic method as generic parameters
What is the use of ad hoc polymorphism?
So that the overloaded subprograms do not behave similarly