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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.42.218.66 with SMTP id hp2mr6733593icb.10.1412631256786; Mon, 06 Oct 2014 14:34:16 -0700 (PDT) X-Received: by 10.50.61.132 with SMTP id p4mr163551igr.1.1412631256703; Mon, 06 Oct 2014 14:34:16 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!uq10no5190286igb.0!news-out.google.com!bc9ni15653igb.0!nntp.google.com!uq10no5190278igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 6 Oct 2014 14:34:16 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: <831a97d3-fa0b-49d9-980b-46e7eb12c1ee@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: specification file ads problem From: Adam Beneschan Injection-Date: Mon, 06 Oct 2014 21:34:16 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4102 X-Received-Body-CRC: 255203227 Xref: news.eternal-september.org comp.lang.ada:22154 Date: 2014-10-06T14:34:16-07:00 List-Id: On Sunday, October 5, 2014 9:20:35 AM UTC-7, mockturtle wrote: > I see an easy error in your code, but I am not sure if it is an error int= roduced by doing cut'n'paste: the spec of your package "MyPackage" ends wi= th "end Neighbours" rather than with "end MyPackage." >=20 >=20 >=20 > Moreover, I think that you should put "N : Integer" before the=20 >=20 > definition of myType since when the compiler sees "type myType is..." doe= s not know what N is. =20 >=20 >=20 >=20 > Moreover, I am not 100% sure that you can use N-1 as array boundary. I k= now you cannot do that in a record declaration.=20 Actually, you *can* do that in a record declaration, as long as "N" isn't a= discriminant. The rules that disallow arithmetic on array bounds in a rec= ord component apply only to discriminants. For a generic formal array type, however, you can't use ranges at all, by R= M 12.5.3(3). The official reason for this, according to the AARM, is "it s= implifies the elaboration of generic_declarations (since there is nothing t= o evaluate), and that it simplifies the matching rules, and makes them more= checkable at compile time." (12.1(7.a)) This rule prohibits both 1..N-1 = on the outer array type and 1..N on the String element type. =20 I don't see a way to get the compiler to check this at compile time. Check= ing at run time is really clunky; this is the only way I could find to get = things to work: generic type String_Index is range <>; type Array_Index is range <>; type String_Subtype is array (String_Index) of Character; type myType is array (Array_Index) of String_Subtype; N : Integer; package myPackage is function tt (a : in String) return myType; end myPackage; package body myPackage is -- define tt=20 begin if String_Index'first /=3D 1 or else Integer(String_Index'last) /=3D N or else Array_Index'first /=3D 1 or else Integer(Array_Index'last) /=3D N - 1 then raise Program_Error with "Instantiation with wrong types"; end if; end myPackage; and to instantiate it, you need something like subtype Integer_3 is integer range 1..3; subtype String3 is String(Integer_3); subtype Integer_2 is integer range 1..2; type Arr is array(Integer_2) of String3; package myPack is new myPackage(Integer_3, Integer_2, String3, Arr, 3); When the instantiation is elaborated, the package body is elaborated, which= causes the code in the "begin..end" of the package body to be executed, wh= ich raises an exception at run time if the array bounds are wrong. I think the design probably needs reworking; to start with, it isn't clear = to me that a generic is needed at all. But it's hard to tell without more = information about what the OP is actually trying to accomplish. -- Adam