6.3 Subprogram Bodies
1
Syntax
2/3
3
Legality Rules
4
Static Semantics
5
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
6
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.
6.a
Ramification: See
12.2
for elaboration of a generic body. Note that protected
subprogram_bodies
never get elaborated; the elaboration of the containing
protected_body
allows them to be called without failing the Elaboration_Check.
7
Examples
8
Example of procedure
body:
9
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;
10
Example of a
function body:
11
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;
Extensions to Ada 83
11.a
Wording Changes from Ada 83
11.b
11.c
11.d
We have incorporated some rules from RM83-6.5
here.
11.e
RM83 forgot to restrict the definition of elaboration
of a
subprogram_body
to non-generics.
Wording Changes from Ada 95
11.f/2
Extensions to Ada 2005
11.g/3
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe