From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Odd array dimension error GNAT
Date: 1998/08/18
Date: 1998-08-18T00:00:00+00:00 [thread overview]
Message-ID: <6rclv0$bk@hacgate2.hac.com> (raw)
In-Reply-To: 35dc97cd.17402128@news.geccs.gecm.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2799 bytes --]
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.:
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.
next parent reply other threads:[~1998-08-18 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 ` David C. Hoos, Sr. [this message]
[not found] ` <35db7934.1130426@news.geccs.gecm.com>
1998-08-19 0:00 ` Odd array dimension error GNAT David C. Hoos, Sr.
[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