TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Proportional Font
Show HTML Part by Default
Condense Mail Headers

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

Print Reply
Sender: "Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
From: "W. Wesley Groleau x4923" <[log in to unmask]>
Date: Tue, 23 Mar 1999 13:44:50 -0500
Reply-To: "W. Wesley Groleau x4923" <[log in to unmask]>
Parts/Attachments: text/plain (115 lines)
I beg your indulgence for a technical question in this advocacy forum.
Our NNTP feed has been broken for months, and I can't seem to get to
comp.lang.ada through any of the other gateways I know of.

In the sample code at the end of this message, one compiler rejects all
four instantiations, citing RM95 12.5.4(3).  Another compiler accepts
them.

The Reference Manual is extremely obscure on this.  I had to do a lot of
looking to conclude that they DO statically match---and of course, I could
be wrong.  :-)  Some of the places I looked are  3.7, 3.10, and 4.9.1
Although notes and examples are "informative" (which I assume means "not
binding" as in LRM 83), it was indeed "informative" to see that 3.8.1 (24,
25, 27) and 3.10 (22, 24) present the same construct.

Opinions?  Since this is the wrong forum for this, please email me
directly instead of to the list.


package Base is

   type Enum is (Int, Char, FP, Str_80);

   Default_Name : constant String := "Undefined";

   type Variant (Discriminant : Enum := Char) is
      record
        Name : String (1 .. Default_Name'Length) := Default_Name;
        case Discriminant is
           when Int =>     FI : Integer;
           when Char =>    FC : Character;
           when FP =>      FF : Float;
           when Str_80 =>  FS : String ( 1 .. 80 );
        end case;

      end record;

   type Acc_Var is access Variant;

end Base;

generic

   type Variable is private;
   type Pointer  is access Variable;

package Take_Up_Space is

   pragma Elaborate_Body (Take_Up_Space);

end Take_Up_Space;

package body Take_Up_Space is

   Memory_Hog : Pointer;

begin

   for I in 1 .. 100 loop

      Memory_Hog := new Variable;

   end loop;

end Take_Up_Space;

with Base;
 use Base;   -- for enum literals

with Take_Up_Space;

with Ada.Text_IO;
 use Ada.Text_IO;

procedure Test_Matching is
   subtype Int_Var is Base.Variant (Int);

   subtype FP_Var is Base.Variant (FP);

   subtype Char_Var is Base.Variant (Char);

   subtype Str_80_Var is Base.Variant (Str_80);

   subtype Int_Ptr is Base.Acc_Var (Int);

   subtype FP_Ptr is Base.Acc_Var (FP);

   subtype Char_Ptr is Base.Acc_Var (Char);

   subtype Str_80_Ptr is Base.Acc_Var (Str_80);

   package Int_Waster is new Take_Up_Space ( Variable => Int_Var,
                                             Pointer  => Int_Ptr );

   package FP_Waster is new Take_Up_Space ( Variable => FP_Var,
                                            Pointer  => FP_Ptr );

   package Char_Waster is new Take_Up_Space ( Variable => Char_Var,
                                              Pointer  => Char_Ptr );

   package Str_80_Waster is new Take_Up_Space ( Variable => Str_80_Var,
                                                Pointer  => Str_80_Ptr );

begin

   null;

exception

   when Storage_Error =>

      Put_Line ("Not enough memory.");

end Test_Matching;

ATOM RSS1 RSS2