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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,18352ac39491e701 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.238.65 with SMTP id vi1mr17412493pbc.7.1340733617261; Tue, 26 Jun 2012 11:00:17 -0700 (PDT) Path: l9ni22815pbj.0!nntp.google.com!news2.google.com!goblin2!goblin.stu.neva.ru!news.karotte.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Why this error, value not in range of subtype of "Standard.Integer"? Date: Tue, 26 Jun 2012 21:00:15 +0300 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 X-Trace: individual.net ugYhg/Gq0qHGOxxic1slBwaSUEy4tDmL9GcFqBIlA3/+glLBCfNID4SlTYubFCv2nD Cancel-Lock: sha1:BdMIdb64pc+F2hruoXKyTVY3gl0= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Date: 2012-06-26T21:00:15+03:00 List-Id: On 12-06-26 18:49 , Nasser M. Abbasi wrote: > experts; > > If I write this, I get an error as show: (notice the B > matrix declaration, that is where the problem is) No, the problem is in the declaration of the A matrix. Or really in the difference in their declarations. > -------------- 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)); The Real_Matrix type is defined in Ada.Numerics.Real_Arrays with Integer as the index type: type Real_Matrix is array (Integer range <>, Integer range <>) of Real'Base; This means that the matrix A, which is constrained by its initial value, has the lower index bounds Integer'First, which in the case of 32-bit integers is -2147483648, and the upper index bound is Integer'First + 2, which is -2147483646. Far out of the range of the indices of B, 1..3. Change the declaration of A to specify the index ranges: A : constant Real_Matrix (1 .. 3, 1 .. 3) := > 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. Yep. Now B also has the index range Integer'First .. Integer'First + 2. > Isn't A'RANGE(1) the same as 1 .. 3 and A'RANGE(2) the same as 1 .. 3? That would be the case, if Real_Matrix were defined with Positive as the index range. But not with Integer. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .