Subprograms Flashcards
Subroutines are the
Fundamental building blocks of programs
Where can subroutines be defined?
Within programs or separately in libraries
What are some other names for a subroutine are (4)
Procedure, routine, method or subprogram
During the execution of a subroutine the caller is
Suspended
Where is the control returned to when a subroutine execution terminates
To the caller
Parameters/formal params are the
Expected values
Actual pamareter/arguments are the
Actual values provided by the calling program
What are the two types of actual/formal parameters
Positional and keyword parameters
Position parameters the binding is done
By the position
Keywords parameters, what are stored together
Formal parameters and corresponding actual parameters
What are the advantages of network parameters
Order is irrelevant
Don’t worry about wrongly ordered parameters
Disadvantages keyword parameters
Users must know and specify the names of formal parameters
What are the two parameters passing methods
Semantic models and implementation models
What are the three distinct semantic models that formal parameters are characterized by?
In mode, out mode, and inout mode
What is inmode?
They can receive data from the corresponding actual parameters
What is out mode?
They can transmit data to the actual parameters
Inout mode
Inmode and out mode
What are the five implementation models?
Pass by value, pass by result, pass by value result, pass by reference and pass by name
What is pass by value
The value of the actual parameter is used to initialize the corresponding formal parameters which then acts as a local variable in the subprogram.
What do pass by value used to implement
In-mode semantics
What are Pass by value implemented by
Copy
What is Pass by result
No value is transmites to a subroutine
The corresponding formal parameter acts as a local variables whose value is transmitted back to the callers actual parameter
What as pass by result used to implement
Out-mode params
What are the pros for pas any result and pass by value?
Fast for scalars (linkage costs and access time)
No side affects to the params