From: "Nasser M. Abbasi" <nma@12000.org>
Subject: Why this error, value not in range of subtype of "Standard.Integer"?
Date: Tue, 26 Jun 2012 10:49:18 -0500
Date: 2012-06-26T10:49:18-05:00 [thread overview]
Message-ID: <jsclls$3bv$1@speranza.aioe.org> (raw)
experts;
If I write this, I get an error as show: (notice the B
matrix declaration, that is where the problem is)
-------------- this does not work ------
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
procedure foo2 is
A : constant Real_Matrix :=
(( 1.0, 2.0, 3.0),
( 4.0, 5.0, 6.0),
( 7.0, 8.0, 9.0));
B : Real_Matrix(1 .. 3,1 .. 3); -- this is the problem
begin
FOR I in A'range(1) LOOP
FOR J in A'range(2) LOOP
B(I,J) := 1.0;
END LOOP;
END LOOP;
end foo2;
-------------------------------
>gnatmake foo2.adb
gcc-4.6 -c foo2.adb
foo2.adb:13:17: warning: value not in range of subtype of "Standard.Integer" defined at line 8
foo2.adb:13:17: warning: "Constraint_Error" will be raised at run time
foo2.adb:13:19: warning: value not in range of subtype of "Standard.Integer" defined at line 8
foo2.adb:13:19: warning: "Constraint_Error" will be raised at run time
gnatbind -x foo2.ali
gnatlink foo2.ali
But if I change the declaration of B from
B : Real_Matrix(1 .. 3,1 .. 3);
to
B : Real_Matrix(A'RANGE(1), A'RANGE(2));
then Ada is happy now.
Isn't A'RANGE(1) the same as 1 .. 3 and A'RANGE(2) the same as 1 .. 3?
or is this one of those typing issues?
---------------------------------------------
with Ada.Numerics.Real_Arrays; use Ada.Numerics.Real_Arrays;
procedure foo1 is
A : constant Real_Matrix :=
(( 1.0, 2.0, 3.0),
( 4.0, 5.0, 6.0),
( 7.0, 8.0, 9.0));
B : Real_Matrix(A'RANGE(1), A'RANGE(2));
begin
FOR I in A'range(1) LOOP
FOR J in A'range(2) LOOP
B(I,J) := 1.0;
END LOOP;
END LOOP;
end foo1;
------------------------------
(one thing I like about Ada, is that once the program compiles clean,
then it runs fine !)
thanks
--Nasser
next reply other threads:[~2012-06-26 15:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-26 15:49 Nasser M. Abbasi [this message]
2012-06-26 17:20 ` Why this error, value not in range of subtype of "Standard.Integer"? Adam Beneschan
2012-06-26 18:00 ` Niklas Holsti
2012-06-26 21:39 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox