DocAda(tm) is a productivity tool of KSCE

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

6.3 Subprogram Bodies

A subprogram_body specifies the execution of a subprogram.

Syntax

   
       subprogram_body ::=
           subprogram_specification is
              declarative_part
           begin
               handled_sequence_of_statements
           end [designator];

Legality Rules

In contrast to other bodies, a subprogram_body need not be the completion of a previous declaration, in which case the body declares the subprogram. If the body is a completion, it shall be the completion of a subprogram_declaration or generic_subprogram_declaration. The profile of a subprogram_body that completes a declaration shall conform fully to that of the declaration.

Static Semantics

A subprogram_body is considered a declaration. It can either complete a previous declaration, or itself be the initial declaration of the subprogram.

Dynamic Semantics

The elaboration of a non-generic subprogram_body has no other effect than to establish that the subprogram can from then on be called without failing the Elaboration_Check.

The execution of a subprogram_body is invoked by a subprogram call. For this execution the declarative_part is elaborated, and the handled_sequence_of_statements is then executed.

Examples

Example of procedure body:

   
       procedure Push(E : in Element_Type; S : in out Stack) is
       begin
          if S.Index = S.Size then
             raise Stack_Overflow;
          else
             S.Index := S.Index + 1;
             S.Space(S.Index) := E;
          end if;
       end Push;

Example of a function body:

    
       function Dot_Product(Left, Right : Vector) return Real is
          Sum : Real := 0.0;
       begin
          Check(Left'First = Right'First and Left'Last = Right'Last);
          for J in Left'Range loop
             Sum := Sum + Left(J)*Right(J);
          end loop;
          return Sum;
       end Dot_Product;

Subclauses

  1. Conformance Rules
  2. Inline Expansion of Subprograms

About DocAda Light: Preface / Preliminary / Help / TOC / Copyright
DocAda Online at the Ada Home: Complete RM95 / Updates / News
Prev | 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