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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,997050aa5cf64c63,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-27 11:31:14 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swrinde!news.dell.com!tadpole.com!uunet!gwu.edu!gwu.edu!not-for-mail From: mfeldman@seas.gwu.edu (Michael Feldman) Newsgroups: comp.lang.ada Subject: Tagged type feature, or GNAT bug? Date: 27 Sep 1994 12:36:30 -0400 Organization: George Washington University Message-ID: <369hme$e9j@felix.seas.gwu.edu> NNTP-Posting-Host: 128.164.9.3 Date: 1994-09-27T12:36:30-04:00 List-Id: -- I'm exploring tagged types as an alternative to variant records. -- Seemingly, one should be permitted to use a classwide type as -- one would an unconstrained variant record. But see below: PROCEDURE TestTags IS -- First a classical Ada 83 variant record -- Note that the record is unconstrained TYPE Kinds IS (A, B, C); TYPE VariantRec (Discrim: Kinds := A) IS RECORD FixedPart: String (1..4); CASE Discrim IS WHEN A => F1: Integer; WHEN B => F2: Float; WHEN C => F3: Boolean; END CASE; END RECORD; -- Now a tagged type equivalent TYPE TaggedRec IS TAGGED RECORD FixedPart: String(1..4); END RECORD; TYPE A_TaggedRec IS NEW TaggedRec WITH RECORD F1: Integer; END RECORD; TYPE B_TaggedRec IS NEW TaggedRec WITH RECORD F2: Float; END RECORD; TYPE C_TaggedRec IS NEW TaggedRec WITH RECORD F3: Boolean; END RECORD; -- OK, some arrays now. -- CASE 1: array of unconstrained variant records. OK in Ada 83. TYPE List IS ARRAY (1..4) OF VariantRec; -- unconstrained variant rec Stuff: List; -- CASE 2: Now an array intended to hold any of the four types -- (by direct analogy with Case 1) -- GNAT rejects this - says the array elements must be constrained TYPE TaggedList IS ARRAY (1..4) OF TaggedRec'Class; TaggedStuff: TaggedList; -- CASE 3: Array of_pointers_ to tagged records -- This will compile OK, but seems a gratuitously required use -- of pointers - very un-Ada-like. TYPE TaggedRecPtr IS ACCESS TaggedRec'Class; TYPE TaggedListPtr IS ARRAY (1..4) OF TaggedRecPtr; TaggedStuffPtr: TaggedList; -- So what is the solution? Perhaps I missed something in 9XRM 5.0, -- but I found nothing to prohibit what I tried to do in Case 2. -- The Ada 9X textbook examples make much of the fact that one -- _can_ use pointers more flexibly in 9X, because e.g. the -- designated objects need not be dynamic. They also show pointers -- as a way that one _can_ do dispatching of operations on tagged-type -- derivatives. It is not clear where (or why) this is the _only_ -- allowed way. -- So did I bump into an Ada 9X feature, or just a GNAT bug? BEGIN NULL; END TestTags; -- Mike Feldman