CSC 218 Notes 4
CSC 218 Notes 4
CSC 218 Notes 4
Lecture Note 4
(Block Structured Languages and Parameter Passing Mechanisms)
Block-structured languages
A class of high-level languages in which a program is made up of blocks – which may
include nested blocks as components, such nesting being repeated to any depth. A block
consists of a sequence of statements and/or blocks, preceded by declarations of
variables. Variables declared at the head of a block are visible throughout the block and
any nested blocks, unless a variable of the same name is declared at the head of an inner
block. In this case the new declaration is effective throughout the inner block, and the
outer declaration becomes effective again at the end of the inner block. Variables are
said to have nested scopes.
The concept of block structure was introduced in the Algol family of languages, and
block-structured languages are sometimes described as Algol-like. The concept of
nested scopes implicit in block structure contrasts with Fortran, where variables are
either local to a program unit (subroutine) or global to several program units if declared
to be COMMON. Both of these contrast with Cobol, where all data items are visible
throughout the entire program.
Example: In Fortran
• The scope of an identifier is the whole program or subprogram.
• Each identifier may be declared only once.
• Variable declarations may be implicit. (Using an identifier implicitly declares it as a
variable.)
• The lifetime of data objects is the whole program.
Parameter passing allows the values of local variables within a main program to be
accessed, updated and used within multiple sub-programs without the need to create or
use global variables.
The mechanism used to pass parameters to a procedure (subroutine) or function. The
most common methods are to pass the value of the actual parameter (call by value), or
to pass the address of the memory location where the actual parameter is stored (call by
reference). The latter method allows the procedure to change the value of the parameter,
whereas the former method guarantees that the procedure will not change the value of
the parameter. Other more complicated parameter-passing methods have been devised,
notably call by name in Algol 60, where the actual parameter is re-evaluated each time
it is required during execution of the procedure.