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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1ce0ce3b2db00698 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.227.67 with SMTP id ry3mr13595007pbc.8.1340730930844; Tue, 26 Jun 2012 10:15:30 -0700 (PDT) Path: l9ni22695pbj.0!nntp.google.com!news1.google.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: how to print an array range? Date: Tue, 26 Jun 2012 10:15:30 -0700 (PDT) Organization: http://groups.google.com Message-ID: <28dde5f5-ad96-4d56-8d7b-5d645d74a15c@googlegroups.com> References: <4fe9bf33$0$6566$9b4e6d93@newsspool4.arcor-online.net> <4fe9daf1$0$6556$9b4e6d93@newsspool4.arcor-online.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1340730930 8980 127.0.0.1 (26 Jun 2012 17:15:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 26 Jun 2012 17:15:30 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-06-26T10:15:30-07:00 List-Id: On Tuesday, June 26, 2012 9:28:21 AM UTC-7, Nasser M. Abbasi wrote: > On 6/26/2012 10:53 AM, Georg Bauhaus wrote: > > On 26.06.12 16:24, Nasser M. Abbasi wrote: > >> But I wanted to see the range of > >> the first dimension of the Matrix A below. (1..3, 1..3) > > > > Specify the ranges you want, for example, > > > > A : constant Real_Matrix (1 .. 3, 1 .. 3) :=3D > > (( 1.0, 2.0, 3.0), > > ( 4.0, 5.0, 6.0), > > ( 7.0, 8.0, 9.0)); > > >=20 > I think I am not explaining myself well. >=20 > I simply wanted to print the range itself, after > I define a variable. using PUT(). >=20 > i.e. in the above, what would one write to > print "1..3" for A'range(1) and "1..3" for A'range(2)? >=20 > I am not asking how to specify the range, I know that. > but to print it, for debugging purposes. >=20 > I can't just type write put(A'range(1)). And when I write > put(A'first(1)) it prints -2147483648. If you declare A the way Georg described, then put(A'first(1)) should print= 1. I think you may have a fundamental misunderstanding about arrays in Ada; yo= u seem to think that the language automatically "knows", in some way, that = the first index of an array is 1. That isn't true. There is no default fi= rst index. (This is unlike some languages like C or Java, where the first = index is always 0; I don't know what it is in MATLAB.) The first index is = whatever you tell the compiler it is. And, as has been pointed out already= , if an unconstrained array type is declared with "Integer range <>" as the= index, and you set up an aggregate without specifying the first index, the= first index will be Integer'first, which is -2147483648 for some Ada compi= lers (the actual value is compiler-dependent). So, if you declare A : constant Real_Matrix :=3D=20 (( 1.0, 2.0, 3.0),=20 ( 4.0, 5.0, 6.0),=20 ( 7.0, 8.0, 9.0));=20 then the first element is at indexes (-2147483648, -2147483648). The last = one is at (-2147483646, -2147483646). If you write A(-2147483648, -2147483= 648) you will get 1.0. If you write A(1,1) you will get a constraint error= . A'First(1) and A'First(2) are both -2147483648. A'Last(1) and A'Last(2)= are both -2147483646. A'Range(1) is a shorthand for A'First(1)..A'Last(1)= . If you want something that tells you that the "first index" is 1 and the= "last index" is 3, you are not going to get it unless you do the math your= self. (But note that A'Length(1) and A'Length(2) are both 3.) That's also= why you're getting the Constraint_Error in your other post. If you say=20 for I in A'Range(1) loop then I will take the values -2147483648, -2147483647, -2147483646; and if y= ou use any of those values as an index into B, which has index ranges (1..3= , 1..3), you'll get a Constraint_Error, because none of those big negative = values is in the range 1..3. My apologies if I'm hammering on stuff you already know. But it just looke= d to me that you had a misconception about how array index ranges work in A= da, since you seemed perplexed by some of the results you were getting. -- Adam