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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable 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 23:41:47 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stueberl.de!teaser.fr!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: christoph.grein@eurocopter.com Newsgroups: comp.lang.ada Subject: Re: strings and multidimensional arrays Date: Tue, 14 Oct 2003 08:24:55 +0200 (MET DST) Organization: Cuivre, Argent, Or Message-ID: Reply-To: grein@egypt.otn.eurocopter.de NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1066113618 13142 80.67.180.195 (14 Oct 2003 06:40:18 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 14 Oct 2003 06:40:18 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: X-Authentication-Warning: mail.eurocopter.com: uucp set sender to using -f Content-MD5: rwNd5N38KStV3tgogt2Huw== X-Mailer: dtmail 1.2.1 CDE Version 1.2.1 SunOS 5.6 sun4u sparc X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:803 Date: 2003-10-14T08:24:55+02:00 > 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. ;-) I think here the language lawyer is in error (even gurus aren't infallible ;-). This has already been legal in Ada83, a wrapper was never needed.