3.2 Procedure Calls

[ Table of Contents ] Prev ] Chapter Overview ] Next ] [ Glossary/Index ]

A procedure call is a simple statement made by stating the procedure name, listing actual parameter names or values within parentheses, and adding a final semi-colon.

General Form

-- where the parameters are separated by commas

The types of the actual parameters must match the types of the formal parameters (if any) that were created when the procedure was originally declared. Otherwise the compiler will refuse to compile the compilation unit in which the call is made.

Here are some code fragments that illustrate two ways of listing the actual parameters while making a procedure call. The first fragment is a procedure declaration (from an earlier example program). The second and third fragments are the example procedure calls.

Source Code Listing

--  This procedure declaration has two formal parameters.
procedure Show_Birthday_Song(First_Name : in String,
                             Last_Name  : in String);
--  The following procedure call uses "positional association." 
--  The first actual parameter is understood to correspond to the 
--  first formal parameter, and the second to the second formal 
--  parameter. 
Show_Birthday_Song("Ada", "Lovelace");  
--  The following procedure call uses "named association."
--  The two parameters could be supplied in either order.
Show_Birthday_Song(First_Name => "Ada";
                   Last_Name  => "Lovelace");  

When reading aloud, you can say, "First_Name gets Ada" and "Last_Name gets Lovelace."

Positional vs Named Association

As you can see from the two examples above, positional association is less verbose, but named association is more self-documenting and understandable. (These two forms are sometimes referred to as "positional notation" and "named notation," respectively.) Another example is given in the next section, where the understandability advantage of named association is made very evident.

It is also possible to mix the two forms in a single call, but in this case it is required that the list begin as a positional list followed by some named-associations.

Rules Regarding the Mode of Parameters

When the mode of a formal parameter is in out or out, the corresponding actual parameter must be a variable. When the mode of a formal parameter is in, the corresponding actual parameter can be a variable, a constant, or an expression.

Rules Regarding Default Parameters

When a formal parameter of mode in has a default value or expression, the actual parameter may be omitted in the call. When the position of a parameter follows that of an omitted parameter, named association must be used.

Related Topics

2.4 Procedures A.2 Simple and Compound Statements

[ Back to top of pagePrev ] Next ]