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-Thread: a07f3367d7,9dcaa9f073e2ef8f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!y7g2000prk.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Type in allocator has deeper level than designated class-wide type Date: Wed, 15 Jun 2011 08:44:25 -0700 (PDT) Organization: http://groups.google.com Message-ID: <900ef224-53c3-4eb1-a8c4-e2a5aca2b9b9@y7g2000prk.googlegroups.com> References: <9bf2ef73-5cc7-4863-90d7-2e2cf3bcd294@o10g2000prn.googlegroups.com> <92fb5bf2-f43e-4ac9-97eb-6092f10e5607@e17g2000prj.googlegroups.com> <6c4421f7-0fbd-49d0-a108-429d542608a2@h12g2000pro.googlegroups.com> <381b180e-9c83-4c6f-a5c9-3b98c2154b82@p9g2000prh.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1308152674 1562 127.0.0.1 (15 Jun 2011 15:44:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 15 Jun 2011 15:44:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y7g2000prk.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19854 Date: 2011-06-15T08:44:25-07:00 List-Id: On Jun 14, 7:04=A0pm, Adrian Hoe wrote: > On Jun 15, 12:01=A0am, Adam Beneschan wrote: > > > > > > > On Jun 14, 1:01=A0am, Adrian Hoe wrote: > > > > But this defeats my implementation intention which the size and the > > > type of its data array can only be determined during runtime. Any > > > suggestion? > > > There was no reason to change the generic parameters to High_Cloud, or > > to change the type of the Data component from Data_Array to Item. =A0As > > I tried to explain, your problem had nothing to do with arrays. =A0The > > problem has to do with where the Element_Record type extension is > > declared, which has to do with where the High_Cloud generic is > > instantiated. =A0In your latest example, you instantiated it directly i= n > > a library package, Hen, so there won't be a problem. =A0If you > > instantiate it inside a procedure, there will be a problem. =A0But the > > types of the components don't matter. > > > If it *does* make a difference---i.e. if declaring Data as a > > Data_Array instead of an Item makes things fail, even if High_Cloud is > > still instantiated directly inside Hen---then I believe the problem is > > with your compiler, and you need to contact your compiler vendor and > > file a bug report. > > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -- = Adam > > Yes, of course both methods are working as long as the instantiation > happens at library level. The implementation of I_Array (e.g. > I_Array_31 to indicate array (1..31) of Integer) in Hen gives the > array a name to describe it, rather than Data_Array as in High_Cloud > in the 1st post. > > Compiler =A0error has been ruled out. > > Is there any other method other than using "generic" package? Again, > the rule is: The data type and the size of the array can only be > determined during runtime. OK, I wasn't really clear on your requirements. (Mostly I was trying to solve your legality issue.) If just the size had to be determined during runtime, I'd suggest using a discriminant record with the size as the discriminant; you could define "Data" as an array whose bound depends on that discriminant (and get rid of the generic formal parameter N). More specifically: type Data_Array is array (Positive range <>) of Item; type Element_Record (N : Positive) is new List.Node with record Name : Unbounded_String; Color : Unbounded_String; Data : Data_Array (1 .. N); end record; But I'm not sure what you mean by "the data type is determined at runtime". In the solution you're trying to use, you instantiate High_Cloud with the upper bound and an Item type, and apparently you're instantiating it inside a procedure. But although the upper bound "N" may be something you have to compute inside the procedure, in most cases the Item type should be something that can be defined outside the procedure. In one of you examples, you seemed to use Integer for the Item type. This means that if you get rid of the generic formal parameter N and make it a record discriminant, as I explained above, you can then instantiate High_Cloud with Item =3D> Integer *outside* the procedure, and then you can still have an Element_Record whose size depends on values you define inside the procedure, but since the type is actually defined outside the procedure, you won't have the access type violation problems. (Note: I have not tried this. I think it will work.) Hopefully that should be enough to solve your problem. But if you still think that the "data type" has to be defined inside the procedure, you'll need to give an example that demonstrates why. Ada doesn't really have the ability to construct new types at runtime. -- Adam