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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3957a46660bc0588 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-13 10:05:46 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!sccrnsc03.POSTED!not-for-mail Message-ID: <3F8ADB3D.5010000@comcast.net> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: strings and multidimensional arrays References: <3F88D320.80706@chartermi.net> <3F88E586.5060809@chartermi.net> <3F89621F.7070406@comcast.net> <3F89EB77.3030007@comcast.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: sccrnsc03 1066064745 24.34.139.183 (Mon, 13 Oct 2003 17:05:45 GMT) NNTP-Posting-Date: Mon, 13 Oct 2003 17:05:45 GMT Organization: Comcast Online Date: Mon, 13 Oct 2003 17:05:45 GMT Xref: archiver1.google.com comp.lang.ada:779 Date: 2003-10-13T17:05:45+00:00 List-Id: Jeffrey Carter wrote: > Is GNAT wrong, or is it unnecessary magic? I've been doing this since > 1984. I know you can't have an array of indefinite elements (an > unconstrained array type, such as String, or a type with unknown > discriminants), but unconstrained records types are not indefinite. Very interesting. I see no problem with your package as written, in fact I see no problem created objects of the array type. (The discriminants will all be assigned the default value One.) But I expected that a record assignment to an element that changed the discriminant would raise Constraint_Error. However, when I created an instance of your array type and assigned to it this is what I got (from GNAT): ---------------------------------------------------------------------- with Ada.Text_IO; use Ada.Text_IO; with Ada.Float_Text_IO; procedure Disc_Test is package Test_Unconstrained_Record_Array is type Disc is (One, Two, Five); type Unconstrained_Record (D : Disc := One) is record case D is when One => I : Integer; when Two => C : Character; when Five => F : Float; end case; end record; type Thing is array (Positive range <>, Positive range <>) of Unconstrained_Record; end Test_Unconstrained_Record_Array; package TURA renames Test_Unconstrained_Record_Array; package TURA_IO is new Ada.Text_IO.Enumeration_IO(TURA.Disc); TT: TURA.Thing(1..5, 1..5); begin TT(1,1) := (TURA.One, 1); TT(2,2) := (TURA.Two, '2'); TT(5,5) := (TURA.Five, 5.0); for I in 1..5 loop Put(" TT(" & Integer'Image(I)(2) & ',' & Integer'Image(I)(2) & ") is "); Put("( D => "); TURA_IO.Put(TT(I,I).D); case TT(I,I).D is when TURA.One => Put(" I =>"); Put(Integer'Image(TT(I,I).I)); when TURA.Two => Put(" C =>"); Put(Character'Image(TT(I,I).C)); when TURA.Five => Put(" I =>"); Ada.Float_Text_IO.Put(TT(I,I).F,2,1,0); end case; Put_Line(")."); end loop; end Disc_Test; ----------------------------------------------------------------------------- E:\Ada\Test>disc_test disc_test TT(1,1) is ( D => ONE I => 1). TT(2,2) is ( D => TWO C =>'2'). TT(3,3) is ( D => ONE I => 2013340188). TT(4,4) is ( D => ONE I => 38010744). TT(5,5) is ( D => FIVE I => 5.0). I'm not going to assert that this is wrong. That would be for the ARG as a whole to do. The key paragraphs of the standard are 3.6(14): "An array_type_definition defines an array type and its first subtype. For each object of this array type, the number of indices, the type and position of each index, and the subtype of the components are as in the type definition[; the values of the lower and upper bounds for each index belong to the corresponding index subtype of its type, except for null arrays (see 3.6.1)]." This is the paragraph that implicitly sets the discriminants for uninitialized components. And 3.6(11): "Within the definition of a nonlimited composite type (or a limited composite type that later in its immediate scope becomes nonlimited -- see 7.3.1 and 7.5), if a component_definition contains the reserved word aliased and the type of the component is discriminated, then the nominal subtype of the component shall be constrained." The first quote implies that the subtype of the components can't be changed, the second implies they can be unless the components are declared as aliased. (Adding the wrapper type allows you to declare the components aliased.) I'll wait to see what Bob Duff, Randy, and possibly Tucker have to say. Certainly this is not documented as a change from Ada 83 in the AARM. But even if it wasn't intended as legal, it is a nice feature. ;-) -- Robert I. Eachus "Quality is the Buddha. Quality is scientific reality. Quality is the goal of Art. It remains to work these concepts into a practical, down-to-earth context, and for this there is nothing more practical or down-to-earth than what I have been talking about all along...the repair of an old motorcycle." -- from Zen and the Art of Motorcycle Maintenance by Robert Pirsig