procedure Average(A, B : in Integer; Result : out Integer);
Actually, a subprogram that averages two numbers would probably be defined as a function. Here's a declaration of a function which takes as input two values and returns a result:
function Average_Two(A, B : in Integer) return Integer;
Note the keywords `in' and `out'; this indicates the mode of the parameter. There are three possible modes:
The default mode is `in', but I recommend that you always state the desired mode.
Here's a BNF for subprogram declarations:
subprogram_declaration ::= subprogram_specification ";" subprogram_specification ::= "procedure" procedure_name parameter_profile | "function" procedure_name parameter_profile "return" type parameter_profile ::= [ "(" parameter_specification { ";" parameter_specification} ")" ] parameter_specification ::= parameter_name_list ":" mode type [ ":=" default_expression ] mode ::= [ "in" ] | "out" | "in" "out" parameter_name_list ::= identifier { "," identifier } procedure_name ::= identifier
Which of the following is not a legal subprogram declaration?
![]() |
![]() |
![]() |
---|
David A. Wheeler (dwheeler@ida.org)