comp.lang.ada
 help / color / mirror / Atom feed
From: "Phil Thornley" <phil.thornley@baesystems.com>
Subject: Re: Anonymous array clarification.
Date: Mon, 20 Aug 2001 09:03:25 +0100
Date: 2001-08-20T09:03:25+01:00	[thread overview]
Message-ID: <3b80c13f$1@pull.gecm.com> (raw)
In-Reply-To: tY1g7.45466$K6.17744072@news2

"McDoobie" <chris@dont.spam.me> wrote in message
news:tY1g7.45466$K6.17744072@news2...
> In Ada one can declare anonymous arrays (an array without a type
assigned
> to it.)  However what would such an array be used for, and are the
bounds
> on it's use the same as for any other type of array.
>
> I guess what I'm asking is if I declare an array such as
>
> some_array : array(1..N);
>

You have to give the component type as well:

some_array : array(1..N) of Integer;  -- or whatever

so the question of how the components are stored doesn't arise.

On the question of what they are used for, I most commonly use them for
look-up tables.

   type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);

   Tomorrow : constant array (Day) of Day
                     := (Tue, Wed, Thu, Fri, Sat, Sun, Mon);

(which avoids a lot of stuff about 'Succ and worrying about
wrap-around).

You can't declare two anonymous arrays of the same type even in the same
declaration:

   A, B : array (1 .. 5) of Integer;

A and B are if different anonymous types and so can't be assigned
(i.e. A := B; is an illegal statement).

Note that an anonymous array can never be passed as the parameter of a
subprogram as you can't name the parameter type.

Cheers,

Phil

--
Phil Thornley
Programmes, Engineering
Warton





  reply	other threads:[~2001-08-20  8:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-20  6:18 Anonymous array clarification McDoobie
2001-08-20  8:03 ` Phil Thornley [this message]
2001-08-20 16:49   ` Tables vs functions (was Re: Anonymous array clarification.) Ray Blaak
2001-08-20 17:28     ` Marin David Condic
2001-08-20 21:02       ` Samuel T. Harris
2001-08-21 14:13         ` Marin David Condic
2001-08-20  8:29 ` Anonymous array clarification David C. Hoos, Sr.
2001-08-20 10:26 ` Larry Hazel
2001-08-20 13:37 ` Samuel T. Harris
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox