Chapter 9 Flashcards

Subprograms

1
Q

Two fundamental abstraction facilities can be included in a programming language, they are?

A

1) process abstraction

2) data abstraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Sub programs have what three characteristics?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A sub program ___ describes the interface to and the actions of the subprogram abstraction.

A

definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

A subprogram ___ is the explicit request that a specific subprogram be executed.

A

call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A subprogram is said to be ___ if after having been called, it has begun execution but has not yet completed that execution.

A

active

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the two fundamental kinds of subprograms?

A

procedures, functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A subprogram ___, is the first part of the definitions and serves several purposes.

A

header

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the purposes of the subprogram header (3)?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The ___ ____ of a subprogram contains the number, order, and types of its formal parameters.

A

parameter profile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The ___ of a subprogram is its parameter profile plus, if it is a function, its return type.

A

protocol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Function declarations are common in C & C++ programs, where they are called ___. Such declarations are often placed in header files.

A

prototypes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The parameters in the subprogram header are called ___ parameters.

A

formal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

actual

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

an effective and safe method of relating actual parameters to their corresponding formal parameters, are called ___ parameters

A

positional

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

____ are collections of statements that define parameterized computations.

A

subprograms

17
Q

What is the difference between a function and procedure subprogram?

A

functions return values and procedures do not

18
Q

What are the two methods in which a procedure can produce a result?

A

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)

19
Q

Design issues associated with subprograms (11).

A

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?

20
Q

Variables that are defined inside subprograms are called ___ variables, because their scope is usually the body of the subprogram in which they are defined.

A

local

21
Q

Formal parameters are characterized by what three distinct semantics models?

A

1) They can receive data - in mode
2) They can transmit data - out-mode
3) They can do both - inout mode

22
Q

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.

A

pass by value

23
Q

__ 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.

A

pass by result

24
Q

__-__-___-__ is an implementation model for inout-mode parameters in which actual values are copied

A

pass-by-value-result

25
Q

Pass-by-value-result is sometimes called __- by-___, because the parameters ___ to the formal parameter at subprogram entry and then ___ back at subprogram termination

A

pass-by-copy, copied, copied

26
Q

__-by-___ is a second implementation model for inout-mode parameters which transmits an access path, such as a pointer, to the called subprogram.

A

Pass-by-reference

27
Q

__-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.

A

Pass-by-name

28
Q

In most contemporary languages, parameter communication takes place through the ___-___ ___.

A

run-time stack

29
Q

The run-time ___ is initialized and maintained by the run-time ___, which manages the execution of programs.

A

stack, system

30
Q

The run-time ___ is used extensively for subprogram control linkage and parameter passing.

A

stack