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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!u9g2000yqb.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: Initialization of Arrays in Ada Date: Wed, 24 Feb 2010 13:30:28 -0800 (PST) Organization: http://groups.google.com Message-ID: <28a44c31-cbe8-4f22-a109-1e954a34e87c@u9g2000yqb.googlegroups.com> References: NNTP-Posting-Host: 82.30.110.254 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1267047028 19142 127.0.0.1 (24 Feb 2010 21:30:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 24 Feb 2010 21:30:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u9g2000yqb.googlegroups.com; posting-host=82.30.110.254; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9308 Date: 2010-02-24T13:30:28-08:00 List-Id: On Feb 24, 9:11=A0pm, Ina Drescher wrote: > Hi Ada Users, > > I have a question concerning the initialization of an array in Ada. > > For instance I have sth. like this: > > arr : Array (Integer Range<>) of Integer:=3D(1=3D>1, 2=3D>2); > > I just want to leave out the 1=3D> 2=3D> ... > > Is there any way like declating undefinite range arrays that ada does > the counting work: > > In C in know this would be like this: > > char name[]=3D"Test" and the compiler counts the number of characters. > > How is this done in Ada ? > I know it's possible to count the number of entries for myself and > then I could eliminate the 1=3D> ... so that it will look like this: > > arr : Array (Integer Range 1..2) of Integer:=3D(1, 2); You might declare the array type first: type Integer_Array is array (Integer range <>) of Integer; Arr : Integer_Array :=3D (1 =3D> 1, 2 =3D> 2); (if you don't do this, you'll have trouble passing Arr to subprograms). You can also write Arr : Integer_Array :=3D (1, 2); but then the indices of Arr are -2147483648 .. -2147483647 (ie, start at Integer'First. Not sure if this is mandated behaviour -- probably -- or just the way GNAT works ...)