From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dad94612ff745427 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bos-service1.raytheon.com!dfw-service2.ext.ray.com.POSTED!53ab2750!not-for-mail Message-ID: <4460B32B.FA67A35F@raytheon.com> From: Jerry Petrey X-Mailer: Mozilla 4.76 [en]C-CCK-MCD CSC;Raytheon (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Instantiating private types with discriminants? References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 09 May 2006 08:20:11 -0700 NNTP-Posting-Host: 147.24.93.107 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.ray.com 1147188009 147.24.93.107 (Tue, 09 May 2006 10:20:09 CDT) NNTP-Posting-Date: Tue, 09 May 2006 10:20:09 CDT Organization: Raytheon Company Xref: g2news2.google.com comp.lang.ada:4158 Date: 2006-05-09T08:20:11-07:00 List-Id: rick H wrote: > Thank you, Georg, Ludovic and Dmitri for your replies. > > Now I know I won't get shouted at for asking novice questions, I have > another query for you experts, if you've got the time to have a look: > > I'm trying to query the tag of a record, which I can do quite nicely, > provided I both "with Ada.Tags" and "use Ada.Tags". Just for the sake > of it, I tried to remove the "use Ada.Tags" statement, but I can't work > out how I would then specify the XXX'Tag attribute of a variable. > Here's an example that illustrates my problem ("if Var_A'Tag..." is the > problem line): > > with Ada.Integer_Text_IO; > with Ada.Float_Text_IO; > with Ada.Tags; > -- use Ada.Tags; > > procedure Simple_Case is > type General_T is tagged null record; > > type Access_T is access General_T'Class; > > type Type_A is new General_T with > record > Data : Integer; > end record; > > type Type_B is new General_T with > record > Data : Float; > end record; > > Var_A : Access_T; -- could be "new Type_A" or a "new Type_B" > begin > -- Var_A := new Type_A' (Data => 100); > Var_A := new Type_B' (Data => 100.0); > > -- problem line: > if Var_A'Tag = Type_A'Tag then > Ada.Integer_Text_IO.Put ( Type_A (Var_A.all).Data); > elsif Var_A'Tag = Type_B'Tag then > Ada.Float_Text_IO.Put ( Type_B (Var_A.all).Data); > end if; > end Simple_Case; You could use function notation for the correct "=" as follows: if Ada.Tags."=" (Var_A'Tag, Type_A'Tag) then Ada.Integer_Text_IO.Put ( Type_A (Var_A.all).Data); elsif Ada.Tags."=" (Var_A'Tag, Type_B'Tag) then Ada.Float_Text_IO.Put ( Type_B (Var_A.all).Data); end if; Jerry -- ------------------------------------------------------------------------ -- Jerry Petrey, GNC Software Engineer, Raytheon Missile Systems -- NOTE: please perform appendectomy on email address before replying ------------------------------------------------------------------------