From: tmoran@acm.org
Subject: Re: discriminant in constraint must appear alone
Date: Tue, 02 Dec 2003 21:15:36 GMT
Date: 2003-12-02T21:15:36+00:00 [thread overview]
Message-ID: <Yh7zb.396856$HS4.3208207@attbi_s01> (raw)
In-Reply-To: vspv69c17kr14c@corp.supernews.com
> > 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;
next prev parent reply other threads:[~2003-12-02 21:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-02 19:43 discriminant in constraint must appear alone Vincent Smeets
2003-12-02 20:56 ` Randy Brukardt
2003-12-02 21:15 ` tmoran [this message]
2003-12-03 9:06 ` Dmitry A. Kazakov
2003-12-03 0:06 ` Robert I. Eachus
2003-12-03 21:02 ` Vincent Smeets
2003-12-04 19:16 ` Randy Brukardt
2003-12-05 0:56 ` info version of Ada Reference Manual Stephen Leake
2003-12-05 1:08 ` Stephane Richard
2003-12-05 1:27 ` Ludovic Brenta
2003-12-05 4:36 ` Fionn mac Cuimhaill
2003-12-05 5:28 ` [Totally OT] Nick Roberts
2003-12-05 14:07 ` info version of Ada Reference Manual Stephen Leake
2003-12-05 14:18 ` Arthur Evans Jr
2003-12-05 14:52 ` Stephen Leake
2003-12-07 15:22 ` Arthur Evans Jr
2003-12-05 14:28 ` Georg Bauhaus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox