Chapter 9 Flashcards
Subprograms
Two fundamental abstraction facilities can be included in a programming language, they are?
1) process abstraction
2) data abstraction
Sub programs have what three characteristics?
1) Each subprogram has a single entry point
2) 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
3) Control always returns to the caller when the subprogram execution terminates
A sub program ___ describes the interface to and the actions of the subprogram abstraction.
definition
A subprogram ___ is the explicit request that a specific subprogram be executed.
call
A subprogram is said to be ___ if after having been called, it has begun execution but has not yet completed that execution.
active
What are the two fundamental kinds of subprograms?
procedures, functions
A subprogram ___, is the first part of the definitions and serves several purposes.
header
What are the purposes of the subprogram header (3)?
1) Specifies that the following syntactic unit is a subprogram definition of some particular kind
2) If the subprogram is not anonymous, provides a name for the program
3) May specify a list of parameters
The ___ ____ of a subprogram contains the number, order, and types of its formal parameters.
parameter profile
The ___ of a subprogram is its parameter profile plus, if it is a function, its return type.
protocol
Function declarations are common in C & C++ programs, where they are called ___. Such declarations are often placed in header files.
prototypes
The parameters in the subprogram header are called ___ parameters.
formal
Subprogram call statements must include the name of the subprogram and a list of parameters to be bound to the formal parameters of the subprogram; these parameters are called ___ parameters.
actual
an effective and safe method of relating actual parameters to their corresponding formal parameters, are called ___ parameters
positional
When a parameter lists is long, ___ parameters, in which the name of the formal parameter to which an actual parameter is to be bound is specified with the actual parameter in a call.
keyword
____ are collections of statements that define parameterized computations.
subprograms
What is the difference between a function and procedure subprogram?
functions return values and procedures do not
What are the two methods in which a procedure can produce a result?
1) Changes a variable that is not part of the formal parameters but is visible by the procedure and calling unit (e.g. global variable)
2) procedure has formal parameters that allow the transfer of data to the caller (e.g. an array)
Design issues associated with subprograms (11).
1) Are local variables statically or dynamically allocated?
2) Can subprogram definitions appear in other subprogram definitions
3) Are the types of the actual parameters checked against the types of the formal parameters
4) If subprograms can be passed as parameters and subprograms can be nested, what is the referencing environment of passed subprogram?
5) Are function side effects allowed?
6) What types of values can be returned from function?
7) How many values can be returned from functions?
8) Can subprograms be overloaded?
9) Can subprograms be generic?
10) If the language allows nested subprograms. are closures supported?
11) What parameter-passing emthod or methods are used?
Variables that are defined inside subprograms are called ___ variables, because their scope is usually the body of the subprogram in which they are defined.
local
Formal parameters are characterized by what three distinct semantics models?
1) They can receive data - in mode
2) They can transmit data - out-mode
3) They can do both - inout mode
When a parameter is ___ by ___, the value of the actual parameter is used to initialize the corresponding formal parameter, which then acts as a local variable in the subprogram, thus implementing in-mode semantics.
pass by value
__ by __ is an implementation model for out-mode parameters where no value is transmitted to the subprogram; the corresponding formal parameter acts as a local variable, but just before control is transferred back to the caller, its value is transmitted back to the caller’s actual parameter.
pass by result
__-__-___-__ is an implementation model for inout-mode parameters in which actual values are copied
pass-by-value-result
Pass-by-value-result is sometimes called __- by-___, because the parameters ___ to the formal parameter at subprogram entry and then ___ back at subprogram termination
pass-by-copy, copied, copied
__-by-___ is a second implementation model for inout-mode parameters which transmits an access path, such as a pointer, to the called subprogram.
Pass-by-reference
__-by-___ is an inout-mode parameter transmission method that does not correspond to a single implementation model. This is where the actual parameter is, in effect, textually substituted for the corresponding formal parameter in all its occurrences in the subprogram.
Pass-by-name
In most contemporary languages, parameter communication takes place through the ___-___ ___.
run-time stack
The run-time ___ is initialized and maintained by the run-time ___, which manages the execution of programs.
stack, system
The run-time ___ is used extensively for subprogram control linkage and parameter passing.
stack