Lecture 27 - November 29, 2007

 

Returned some work

 

Quiz on chapter 7

 

Chapter 9 - fundamentals of  subprograms

·         subprogram

o       definition

o       calls

o        active

o        header

o       parameter profile (signature)

o       protocol  (signature + return value)

o       prototype (like the Ada specification)

·         parameters

o       formal parameters

o       actual parameters

o       positional parameters

o       keyword parameters  (named parameters)

·         subprogram types

o       procedures  (e.g. subroutines in FORTRAN)

o       functions  (i.e. methods in Java)

·         important questions

o       parameter passing method(s) used

o       are types of actual and formal checked

o       are local variables statically or dynamically allocated

o       if subprograms can be passed as parameters and subprograms can be nested, what is the referencing environment of a  passed subprogram?

o       can subprograms be overloaded

function “<”  ( a, b : in  myArray) is

  result : boolean;

Begin

 Result := true;

for I in myArray’first .. myArray’last loop

        if (a(i) >= b(i) ) then

           Result := false;

        End if;

End loop;

Return result;

End “<”;

 

Myboolean :=  “<”(myArrayA, myArrayB);

o       can subprograms be generic

·         local variables

·         parameter-passing methods

o       formal parameters are characterized by one of three distinct semantics models

§         they can received data from the corresponding actual parameter

§         they can transmit (send) data to the actual parameter

§         they can do both

o       pass by value

o       pass by result

o       pass by value/result

o       pass by reference

o       pass by name

o        

·         which languages use which parameter passing mode

o       C uses pass by value but can get pass by reference using pointers as parameters

o       Ada uses pass by value, pass by result, pass by value/result

o       FORTRAN uses pass by reference

o       Pascal uses pass by value, pass by reference

o       C# uses pass by value but can achieve pass by reference

·         type checking of parameters

·         multi-dimensional arrays as parameters

·         parameters that are subprogram names

·         overloaded subprograms

·         generic subprograms

 

Parameter passing modes

 

PassByValue.jpg

 

PassByLocation.jpg

 

PassByResult.jpg

 

PassByName.jpg