comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Odd array dimension error GNAT
Date: 1998/08/19
Date: 1998-08-19T00:00:00+00:00	[thread overview]
Message-ID: <sjS95p1y9GA.180@samson.airnet.net> (raw)
In-Reply-To: 35db7934.1130426@news.geccs.gecm.com

Brian Orpin wrote in message <35db7934.1130426@news.geccs.gecm.com>...
>On Tue, 18 Aug 1998 14:49:34 -0500, "David C. Hoos, Sr."
><david.c.hoos.sr@ada95.com> 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 <G>).
>
>>>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?
>
><LRM snipped>
>
>>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.







  parent reply	other threads:[~1998-08-19  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <35dc97cd.17402128@news.geccs.gecm.com>
1998-08-18  0:00 ` Odd array dimension error GNAT David C. Hoos, Sr.
     [not found]   ` <35db7934.1130426@news.geccs.gecm.com>
1998-08-19  0:00     ` David C. Hoos, Sr. [this message]
     [not found]       ` <35dfb078.15280421@news.geccs.gecm.com>
1998-08-19  0:00         ` David C. Hoos, Sr.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox