TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Proportional Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tucker Taft <[log in to unmask]>
Reply To:
Date:
Wed, 14 Jul 1999 12:25:12 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (98 lines)
Christoph & Ursula Grein wrote:
>
> Given the following declarations:
>
> declare
>
>   type M is (A, E);
>
>   type R (D: M := M'First )is  record
>     case D is
>       when A => AS: Integer;
>       when E => ES: Float;
>     end case;
>   end record;
>
>   subtype RA is r (A);
>   subtype RE is R (E);
>
>   procedure Ass (D: M; Z: out R) is
>   begin
>     case D is
>       when A => Z := (A, 1);
>       when E => Z := (E, 1.0);
>     end case;
>   end Ass;
>
>   procedure AssA (Z: out RA) is
>   begin
>     Z := (A, 1);
>   end AssA;
>
>   procedure AssE (Z: out RE) is
>   begin
>     Z := (E, 1.0);
>   end AssE;
>
>   procedure AssAE (D: M; Z: out R) is
>   begin
>     case D is
>       when A => AssA (Z);
>       when E => AssE (Z);
>     end case;
>   end AssAE;
>
>   Z: R;
>
>   ZA: R (A);
>   ZE: R (E);
>
> begin
>
>   Ass (E, Z);     -- ok
>
>   AssAE (A, Z);   -- Constraint_Error, discriminant E
>   AssAE (A, ZA);  -- ok
>
> end;
>
> What is the deeper reason for the rules RM_95 6.4.1(14,16)) forcing that
> for out parameters with constrained formals, the discriminant of the actual
> must match already before the call, for unconstrained formals the dicriminant
> of the actual changes as appropriate?

The subtype of the formal applies throughout the lifetime of the formal,
even for an OUT parameter.  For example, if you have an OUT parameter
of type RA, you may presume throughout the procedure that the value
of the discriminant is A, even before you do a whole-object assignment
to the formal.  Hence, you could assign just into the AS field of the
formal, without needing to verify that D = A.

Even for an OUT parameter, the discriminants may be presumed initialized
prior to the call, to values that match the constraints of the formal
subtype.

>
> I'm aware of AARM_95 6.4.1(17e).
>
>                                  o     _      _          _
>  --------- __o       __o      /\_    _ \\o   (_)\__/o   (_)
>  ------- _`\<,_    _`\<,_    _>(_)  (_)/<_     \_| \    _|/' \/
>  ------ (_)/ (_)  (_)/ (_)  (_)         (_)    (_)     (_)'  _\o_
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Mein Radunfall
> My bike accident
>
> Christoph Grein
> Mitglied von Ada-Deutschland
> Member of Ada Germany
> http:/www.ada-deutschland.de
>
> http://home.T-Online.de/home/Christ-Usch.Grein
> eMail: [log in to unmask]

--
-Tucker Taft   [log in to unmask]   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA

ATOM RSS1 RSS2