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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6e8cd190abfc4972 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Odd array dimension error GNAT Date: 1998/08/19 Message-ID: #1/1 X-Deja-AN: 382595458 References: <35dc97cd.17402128@news.geccs.gecm.com> <6rclv0$bk@hacgate2.hac.com> <35db7934.1130426@news.geccs.gecm.com> Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Date: 1998-08-19T00:00:00+00:00 List-Id: Brian Orpin wrote in message <35db7934.1130426@news.geccs.gecm.com>... >On Tue, 18 Aug 1998 14:49:34 -0500, "David C. Hoos, Sr." > wrote: > >>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.: > >How come the first one compiles? > > > >>Since the dimensionality of your arrays is 2, N can only be 1 or 2. > >But I should still be able to use 'first and 'last as 'first should >return 1 and 'last 2. Not so. NOTE: The value of T1'First is implicitly T1'First (1), and, therefore is1 The value of T1'Last is implicitly T1'Last (1), and, therefore is 3 The value of T2'First is implicitly T2'First (1), and, therefore is 1 The value of T2'Last is implicitly T2'Last (1), and, therefore is 10 The value of T1'First (2) is 1 The value of T1'Last (2) is 10 The value of T2'First (2) is 1 The value of T2'Last (2) is 3 If you don't believe it, print the Integer'Image oif each of the above expressions to see what the values are. >>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; > >But this is no less static than using 'first and ' last. Agreed. But staticness is not the issue here. The values are plain wrong. > It is also >useless because it assumes that the array will always be of range 1..2. >what if it was 0..1?? > Wrong, It assumes the _dimension_ (i.e., the number of subscripts) of the arrays is always 2. Is not this correct? Perhaps another way of stating this is that there is no Ada attribute returning the _dimensionality_ of an array. The dimension to which the attributes 'First, 'Last, 'Length and 'Range apply must be specified, either explicitly or implicitly (in whch case the applicable dimension is the first index). >PS I forgot to mention that this is Ada 83 only so no clever 95 stuff >thanks. You did mention the Ada83 RM, and although I quoted from the Ada95 RM, because that's what I have handy in electronic form, this aspect of the language is unchanged.