6.1 Subprogram Declarations
1
Syntax
2/2
3/2
This paragraph
was deleted.
4/2
4.1/2
4.2/2
5
6
7
8
9
10/2
The sequence of characters in an
operator_symbol
shall form a reserved word, a delimiter, or compound delimiter that corresponds
to an operator belonging to one of the six categories of operators defined
in clause
4.5.
11
12
13/2
14
15/2
16
mode ::= [
in] |
in out |
out
Name Resolution Rules
17
A
formal parameter is
an object directly visible within a
subprogram_body
that represents the actual parameter passed to the subprogram in a call;
it is declared by a
parameter_specification.
For a formal parameter, the expected type for its
default_expression,
if any, is that of the formal parameter.
Legality Rules
18
The
parameter mode of
a formal parameter conveys the direction of information transfer with
the actual parameter:
in,
in out, or
out. Mode
in
is the default, and is the mode of a parameter defined by an
access_definition.
The formal parameters of a function, if any, shall have the mode
in.
19
20/2
21
Static Semantics
22
The
profile of (a view
of) a callable entity is either a
parameter_profile
or
parameter_and_result_profile;
it embodies information about the interface to that entity — for
example, the profile includes information about parameters passed to
the callable entity. All callable entities have a profile — enumeration
literals, other subprograms, and entries. An access-to-subprogram type
has a designated profile. Associated with a profile is a calling convention.
A
subprogram_declaration
declares a procedure or a function, as indicated by the initial reserved
word, with name and profile as given by its specification.
23/2
24/2
An
access parameter is
a formal
in parameter specified by an
access_definition.
An
access result type is a function result
type specified by an
access_definition.
An access parameter or result type is of an anonymous access type (see
3.10). Access parameters of an access-to-object
type allow dispatching calls to be controlled by access values. Access
parameters of an access-to-subprogram type permit calls to subprograms
passed as parameters irrespective of their accessibility level.
25
The
subtypes of a profile are:
26
- For any non-access parameters, the
nominal subtype of the parameter.
27/2
- For any access parameters of an access-to-object
type, the designated subtype of the parameter type.
27.1/2
- For any access parameters of an access-to-subprogram
type, the subtypes of the profile of the parameter type.
28/2
- For any non-access result, the nominal
subtype of the function result.
28.1/2
- For any access result type of an access-to-object
type, the designated subtype of the result type.
28.2/2
- For any access result type of an access-to-subprogram
type, the subtypes of the profile of the result type.
29
The
types of a profile
are the types of those subtypes.
30/2
30.1/2
Dynamic Semantics
31/2
32
33
34
3 The evaluation of
default_expressions
is caused by certain calls, as described in
6.4.1.
They are not evaluated during the elaboration of the subprogram declaration.
35
4 Subprograms can be called recursively
and can be called concurrently from multiple tasks.
Examples
36
Examples of subprogram
declarations:
37
procedure Traverse_Tree;
procedure Increment(X :
in out Integer);
procedure Right_Indent(Margin :
out Line_Size); --
see 3.5.4
procedure Switch(From, To :
in out Link); --
see 3.10.1
38
function Random
return Probability; --
see 3.5.7
39
function Min_Cell(X : Link)
return Cell; --
see 3.10.1
function Next_Frame(K : Positive)
return Frame; --
see 3.10
function Dot_Product(Left, Right : Vector)
return Real; --
see 3.6
40
function "*"(Left, Right : Matrix)
return Matrix; --
see 3.6
41
Examples of in
parameters with default expressions:
42
procedure Print_Header(Pages :
in Natural;
Header :
in Line := (1 .. Line'Last => ' '); --
see 3.6
Center :
in Boolean := True);