DocAda(tm) is a productivity tool of KSCE

____ | Up | Next | Back | Forward
About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News

6.1 Subprogram Declarations

A subprogram_declaration declares a procedure or function.

Syntax

   
       subprogram_declaration ::= subprogram_specification;

       abstract_subprogram_declaration ::= subprogram_specification is abstract;

       subprogram_specification ::=
            procedure defining_program_unit_name  parameter_profile
          | function defining_designator  parameter_and_result_profile

       designator ::= [parent_unit_name . ]identifier | operator_symbol

       defining_designator ::= defining_program_unit_name | defining_operator_symbol

       defining_program_unit_name ::= [parent_unit_name . ]defining_identifier
   
       operator_symbol ::= string_literal
    
       defining_operator_symbol ::= operator_symbol

       parameter_profile ::= [formal_part]

       parameter_and_result_profile ::= [formal_part] return subtype_mark

       formal_part ::=
          (parameter_specification {; parameter_specification})

       parameter_specification ::=
           defining_identifier_list : mode  subtype_mark [:= default_expression]
         | defining_identifier_list : access_definition [:= default_expression]

       mode ::= [in] | in out | out

Name Resolution Rules

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

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.

A default_expression is only allowed in a parameter_specification for a formal parameter of mode in.

A subprogram_declaration or a generic_subprogram_declaration requires a completion: a body, a renaming_declaration (see 8.5), or a pragma Import (see B.1). A completion is not allowed for an abstract_subprogram_declaration.

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

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.

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.

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 3.10). Access parameters allow dispatching calls to be controlled by access values.

The subtypes of a profile are:

The types of a profile are the types of those subtypes.

A subprogram declared by an abstract_subprogram_declaration is abstract; a subprogram declared by a subprogram_declaration is not. See 3.9.3, ``Abstract Types and Subprograms''.

Dynamic Semantics

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

Examples

Examples of subprogram declarations:

    
       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

       function Random return Probability;                      --  see 3.5.7

       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

       function "*"(Left, Right : Matrix) return Matrix;        --  see 3.6

Examples of in parameters with default expressions:

    
       procedure Print_Header(Pages  : in Natural;
                   Header : in Line    :=  (1 .. Line'Last => ' ');  --  see 3.6
                   Center : in Boolean := True);

About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News
____ | Up | Next | Back | Forward


Copyright © 1994-1997 by Kempe Software Capital Enterprises. All Rights Reserved. For comments on this DocAda(tm) hypertext document, please write to KSCE, at docada@ksce.com