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=-0.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,6e8cd190abfc4972,start X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Odd array dimension error GNAT Date: 1998/08/18 Message-ID: <6rclv0$bk@hacgate2.hac.com>#1/1 X-Deja-AN: 382387232 References: <35dc97cd.17402128@news.geccs.gecm.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: Hughes Aircraft Company Newsgroups: comp.lang.ada Date: 1998-08-18T00:00:00+00:00 List-Id: Brian Orpin wrote in message <35dc97cd.17402128@news.geccs.gecm.com>... >Trying to swap the dimensions of 2 arrays (if anyone has a simpler way >feel free ). > >The query is why GNAT raises an error in the last set of loops where I >have used a 'Last as opposed to the previous loop where I used a 'First + >1. Very simply because your code violates the RM, viz.: 3.6.2 Operations of Array Types Legality Rules 1 The argument N used in the attribute_designators for the N-th dimension of an array shall be a static expression of some integer type. The value of N shall be positive (nonzero) and no greater than the dimensionality of the array. Static Semantics 2 The following attributes are defined for a prefix A that is of an array type (after any implicit dereference), or denotes a constrained array subtype: 3 A�First A�First denotes the lower bound of the first index range; its type is the corresponding index type. 4 A�First(N) A�First(N) denotes the lower bound of the N-th index range; its type is the corresponding index type. 5 A�Last A�Last denotes the upper bound of the first index range; its type is the corresponding index type. 6 A�Last(N) A�Last(N) denotes the upper bound of the N-th index range; its type is the corresponding index type. 7 A�Range A�Range is equivalent to the range A�First .. A�Last, except that the prefix A is only evaluated once. 8 A�Range(N) A�Range(N) is equivalent to the range A�First(N) .. A�Last(N), except that the prefix A is only evaluated once. 9 A�Length A�Length denotes the number of values of the first index range (zero for a null range); its type is universal_integer. 10 A�Length(N) A�Length(N) denotes the number of values of the N-th index range (zero for a null range); its type is universal_integer. Since the dimensionality of your arrays is 2, N can only be 1 or 2. Note also the following from the same section of the RM: NOTES 12 45 The attribute_references A�First and A�First(1) denote the same value. A similar relation exists for the attribute_references A�Last, A�Range, and A�Length. The following relation is satisfied (except for a null array) by the above attributes if the index type is an integer type: 13 A'Length(N) = A'Last(N) � A'First(N) + 1 Therefore your code (applicable fragment) should be: Begin -- set some meaningful values For I In T1'Range(1) Loop For J In T1'Range(2) loop OLD_ARRAY(I,J) := COUNT; COUNT := COUNT + 1; End Loop; End Loop; -- swap the arrays NEW_ARRAY := SWAP (OLD_ARRAY); -- print the results For I In T2'Range(1) Loop For J In T2'Range(2) loop TEXT_IO.PUT(INTEGER'Image(NEW_ARRAY(I,J))&" "); End Loop; End Loop; End TEST; David C. Hoos, Sr.