Go to the first, previous, next, last section, table of contents.

6.1 Subprogram Declarations

  1. A subprogram_declaration declares a procedure or function.


  2. subprogram_declaration ::= subprogram_specification;
  3. abstract_subprogram_declaration ::=
       subprogram_specification is abstract;
  4. subprogram_specification ::=
         procedure defining_program_unit_name parameter_profile
       | function defining_designator parameter_and_result_profile
  5. designator ::= [parent_unit_name . ]identifier | operator_symbol
  6. defining_designator ::=
       defining_program_unit_name | defining_operator_symbol
  7. defining_program_unit_name ::=
       [parent_unit_name . ]defining_identifier
    1. The optional parent_unit_name is only allowed for library units, See section 10.1.1 Compilation Units - Library Units.

  1. operator_symbol ::= string_literal
    1. The sequence of characters in an operator_symbol shall correspond to an operator belonging to one of the six classes of operators defined in clause See section 4.5 Operators and Expression Evaluation (spaces are not allowed and the case of letters is not significant).

  1. defining_operator_symbol ::= operator_symbol
  2. parameter_profile ::= [formal_part]
  3. parameter_and_result_profile ::= [formal_part] return subtype_mark
  4. formal_part ::=
       (parameter_specification {; parameter_specification{)
  5. parameter_specification ::=
        defining_identifier_list : mode subtype_mark
          [:= default_expression]
      | defining_identifier_list : access_definition
          [:= default_expression]
  6. mode ::= [in] | in out | out

    Name Resolution Rules

  7. 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

  8. 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.
  9. A default_expression is only allowed in a parameter_specification for a formal parameter of mode in.
  10. A subprogram_declaration or a generic_subprogram_declaration requires a completion: a body, a renaming_declaration, See section 8.5 Renaming Declarations, or a pragma Import, See section B.1 Interfacing Pragmas. A completion is not allowed for an abstract_subprogram_declaration.
  11. A name that denotes a formal parameter is not allowed within the formal_part in which it is declared, nor within the formal_part of a corresponding body or accept_statement.

    Static Semantics

  12. 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.
  13. The nominal subtype of a formal parameter is the subtype denoted by the subtype_mark, or defined by the access_definition, in the parameter_specification.
  14. An access parameter is a formal in parameter specified by an access_definition. An access parameter is of an anonymous general access-to-variable type, See section 3.10 Access Types. Access parameters allow dispatching calls to be controlled by access values.
  15. The subtypes of a profile are:
    1. For any non-access parameters, the nominal subtype of the parameter.
    2. For any access parameters, the designated subtype of the parameter type.
    3. For any result, the result subtype.

  1. The types of a profile are the types of those subtypes.
  2. A subprogram declared by an abstract_subprogram_declaration is abstract; a subprogram declared by a subprogram_declaration is not. See section 3.9.3 Abstract Types and Subprograms.

    Dynamic Semantics

  3. The elaboration of a subprogram_declaration or an abstract_subprogram_declaration has no effect.


  4. (1) A parameter_specification with several identifiers is equivalent to a sequence of single parameter_specifications, as explained in 3.3.
  5. (2) Abstract subprograms do not have bodies, and cannot be used in a nondispatching call, See section 3.9.3 Abstract Types and Subprograms.
  6. (3) The evaluation of default_expressions is caused by certain calls, as described in See section 6.4.1 Parameter Associations. They are not evaluated during the elaboration of the subprogram declaration.
  7. (4) Subprograms can be called recursively and can be called concurrently from multiple tasks.


  8. Examples of subprogram declarations:
  9. procedure Traverse_Tree;
    procedure Increment(X : in out Integer);
    procedure Right_Indent(Margin : out Line_Size); --  See section 3.5.4 Integer Types
    procedure Switch(From, To : in out Link);       --  See section 3.10.1 Incomplete Type Declarations
  10. function Random return Probability;             --  See section 3.5.7 Floating Point Types
  11. function Min_Cell(X : Link) return Cell;        --  See section 3.10.1 Incomplete Type Declarations
    function Next_Frame(K : Positive) return Frame; --  See section 3.10 Access Types
    function Dot_Product(Left, Right : Vector) return Real;
    --  See section 3.6 Array Types
  12. function "*"(Left, Right : Matrix) return Matrix;
    --  See section 3.6 Array Types
  13. Examples of in parameters with default expressions:
  14. procedure Print_Header
      (Pages  : in Natural;
       Header : in Line    :=  (1 .. Line'Last => ' '); --  See section 3.6 Array Types
       Center : in Boolean := True);

Go to the first, previous, next, last section, table of contents.