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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f20f5dfbb5c26c12 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-02 13:15:37 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!crtntx1-snh1.gtei.net!news.gtei.net!newsfeed1.easynews.com!easynews.com!easynews!elnk-pas-nf1!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!wn13feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!attbi_s01.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: discriminant in constraint must appear alone References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 24.6.133.123 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s01 1070399736 24.6.133.123 (Tue, 02 Dec 2003 21:15:36 GMT) NNTP-Posting-Date: Tue, 02 Dec 2003 21:15:36 GMT Organization: Comcast Online Date: Tue, 02 Dec 2003 21:15:36 GMT Xref: archiver1.google.com comp.lang.ada:3078 Date: 2003-12-02T21:15:36+00:00 List-Id: > > I want to define a discriminated record type with two arrays. One array > only half the size > > of the other. Below is the type definition that I want to use. > > > > type R (D : Positive) is > > record > > A : String (1 .. D); > > B : String (1 .. D / 2); > > end record; > >Are there other possiblities? > type R (D1, D2 : Positive) is new Ada.Finalization.Controlled with If you use Controlled, then this could be one of those occasions where access types are really useful. type String_Ptr_Type is access String; procedure Free is new Ada.Unchecked_Conversion(String, String_Ptr_Type); type R (D : Positive) is record A : String_Ptr_Type; B : String_Ptr_Type; end record; Then "R.A" needs to be "R.A.all", but R.A(i) can stay untouched. procedure Initialize (Obj : in out R) is begin A := new String(1 .. Obj.D); B := new String(1 .. Obj.D/2); end Initialize; procedure Finalize (Obj : in out R) is begin Free(Obj.B); Free(Obj.A); end Finalize;