6.1 Subprogram Declarations
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 subclause 4.5
The “sequence of characters” of the string literal of the
operator is a technical term (see 2.6
does not include the surrounding quote characters. As defined in 2.2
lexical elements are “formed” from a sequence of characters.
Spaces are not allowed, and upper and lower case is not significant.
Only implementation-defined aspects are allowed
on formal parameters in Ada 2022. Implementers are cautioned that any
aspect allowed on a formal parameter will need conformance rules. If,
for instance, an aspect changed the representation of a parameter, rules
would be needed to ensure that the representation is the same for the
specification and body.
] | in out
Name Resolution Rules
A formal parameter
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
if any, is that of the formal parameter.
The parameter mode
of a formal parameter conveys
the direction of information transfer with the actual parameter: in
, or out
. Mode in
is the default, and is the
mode of a parameter defined by an access_definition
Abstract subprograms , null procedures, and expression functions are
not declared by subprogram_declaration
and so do not require completion (although the latter two can be
completions). Protected subprograms are declared by subprogram_declaration
and so require completion. Note that an abstract subprogram is a subprogram,
a null procedure is a subprogram, an expression function is a subprogram,
and a protected subprogram is a subprogram, but a generic subprogram
is not a subprogram.
When the Import aspect is True for any entity, no completion is allowed
of (a view
of) a callable entity is either a parameter_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.
declares a procedure or a function, as indicated by the initial reserved
word, with name and profile as given by its specification.
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
). [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.]
Access result types have normal accessibility and thus don't have any
special properties worth noting here.
subtypes of a profile
For any non-access parameters, the nominal subtype
of the parameter.
For any access parameters of an access-to-object type, the designated
subtype of the parameter type.
For any access parameters of an access-to-subprogram type, the subtypes
of the designated profile of the parameter type.
For any access result type of an access-to-object type, the designated
subtype of the result type.
For any access result type of an access-to-subprogram type, the subtypes
of the designated profile of the result type.
The types of a profile
are the types of those subtypes.]
NOTE 3 The evaluation of default_expression
is caused by certain calls, as described in 6.4.1
They are not evaluated during the elaboration of the subprogram declaration.
NOTE 4 Subprograms can be called
recursively and can be called concurrently from multiple tasks.
Examples of subprogram
Increment(X : in out
Right_Indent(Margin : out
Line_Size); -- see 3.5.4
Switch(From, To : in out
Link); -- see 3.10.1
Probability; -- see 3.5.7
Min_Cell(X : Link) return
Cell; -- see 3.10.1
Next_Frame(K : Positive) return
Frame; -- see 3.10
Dot_Product(Left, Right : Vector) return
Real; -- see 3.6
function Find(B : aliased in out Barrel; Key : String) return Real;
-- see 4.1.5
"*"(Left, Right : Matrix) return
Matrix; -- see 3.6
Examples of in
parameters with default expressions:
Print_Header(Pages : in
Header : in
Line := (1 .. Line'Last => ' '); -- see 3.6
Center : in
Boolean := True);
Extensions to Ada 83
Wording Changes from Ada 83
We have incorporated the rules from RM83-6.5,
“Function Subprograms” here and in 6.3
We have incorporated the definitions of RM83-6.6,
“Parameter and Result Type Profile - Overloading of Subprograms”
Extensions to Ada 95
The return type of a function can be an anonymous access type.
Wording Changes from Ada 95
A description of the purpose of anonymous access-to-subprogram parameters
and the definition of the profile of subprograms containing them was
Extensions to Ada 2005
Parameters can now be explicitly aliased, allowing
parts of function results to designate parameters and forcing by-reference
The parameters of a function can now have any mode.
Wording Changes from Ada 2005
Extensions to Ada 2012
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe