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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,83f37cdf3c91adc6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-02 12:00:03 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!out.nntp.be!propagator2-sterling!news-in.nuthinbutnews.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny02.gnilink.net.POSTED!53ab2750!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: <67ac8b2c.0305020925.6c27576d@posting.google.com> Subject: Re: variant record and pointer X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: Date: Fri, 02 May 2003 19:00:02 GMT NNTP-Posting-Host: 151.203.13.241 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny02.gnilink.net 1051902002 151.203.13.241 (Fri, 02 May 2003 15:00:02 EDT) NNTP-Posting-Date: Fri, 02 May 2003 15:00:02 EDT Xref: archiver1.google.com comp.lang.ada:36883 Date: 2003-05-02T19:00:02+00:00 List-Id: This is your question, but have you considered using tagged types instead of variant records? You could declare your shape types as follows: type Shape; type Pointer is access all Shape'Class; type Shape is abstract tagged record Ptr : Pointer; Special : Unbounded_String; end record; type Circle is new Shape with record Diameter : Natural; end record; type Square is new Shape with record Side : Natural; end record; type Triangle is new Shape with record Edge_1, Edge_2, Edge_3 : Natural; end record; This would allow you to derive additional shapes (for example, Rectangle) later, without impacting existing code. Moreover, you could write overloaded subprograms that can dispatch at runtime, e.g. function Perimeter( X : in Shape ) return Float is abstract; function Perimeter( X : in Circle ) return Float; function Perimeter( X : in Square ) return Float; function Perimeter( X : in Triangle ) return Float; -- ... Pointer s; -- Len := Perimeter( s.all ); -- This calls the right Perimeter function, -- even if we cannot determine the type of s.all until runtime.