comp.lang.ada
 help / color / mirror / Atom feed
From: sjw <simon.j.wright@mac.com>
Subject: Re: Initialization of Arrays in Ada
Date: Wed, 24 Feb 2010 13:30:28 -0800 (PST)
Date: 2010-02-24T13:30:28-08:00	[thread overview]
Message-ID: <28a44c31-cbe8-4f22-a109-1e954a34e87c@u9g2000yqb.googlegroups.com> (raw)
In-Reply-To: d7d8271e-9b42-4c77-ab26-83c56c481606@f8g2000yqn.googlegroups.com

On Feb 24, 9:11 pm, Ina Drescher <ina.drescher.1...@googlemail.com>
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:=(1=>1, 2=>2);
>
> I just want to leave out the 1=> 2=> ...
>
> 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[]="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=> ... so that it will look like this:
>
> arr : Array (Integer Range 1..2) of Integer:=(1, 2);

You might declare the array type first:

   type Integer_Array is array (Integer range <>) of Integer;

   Arr : Integer_Array := (1 => 1, 2 => 2);

(if you don't do this, you'll have trouble passing Arr to
subprograms).

You can also write

   Arr : Integer_Array := (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 ...)




  parent reply	other threads:[~2010-02-24 21:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-24 21:11 Initialization of Arrays in Ada Ina Drescher
2010-02-24 21:30 ` Ludovic Brenta
2010-02-24 21:30 ` sjw [this message]
2010-02-24 21:52   ` Jeffrey R. Carter
2010-02-24 23:50     ` Randy Brukardt
2010-02-25  0:01     ` 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