comp.lang.ada
 help / color / mirror / Atom feed
From: matthew_heaney@acm.org (Matthew Heaney)
Subject: Re: Variable-length arrays (from a C programmer)
Date: 1998/04/28
Date: 1998-04-28T00:00:00+00:00	[thread overview]
Message-ID: <matthew_heaney-ya023680002804982248550001@news.ni.net> (raw)
In-Reply-To: 353F9B75.3019A7A4@AlliedSignal.com


In article <353F9B75.3019A7A4@AlliedSignal.com>, "Paul T. McAlister"
<Paul.McAlister@AlliedSignal.com> wrote:

(start of quote)
In "C" (see example), I can define an array of messages for each page,
then define an array of pages for the whole thing.
I don't have to worry about string length or number of items defined in
the arrays, the compiler handles all of that for me.

I have not been able to figure out how to do the equivalent thing in
Ada.
I don't know how to define strings without setting the length to the
maximum length string I will have, which wastes a lot of space.
I think I know how to define the variable length arrays for the messages
for each screen, but I don't know how to define an array type of these
arrays of string for each page (since they are different types because
they are different lengths).
I am using Ada83.
(end of quote)

You stated clearly that you are using Ada 83.  However, I wanted to let you
know that in Ada 95 there's a predefined string type that does exactly what
you want.  It's called Ada.Strings.Unbounded.Unbounded_String.

In Ada 83, you'll have to roll your own dynamic string abstraction,
something like

package Unbounded_Strings is

   type Unbounded_String is limited private;

   procedure Append (S : String; To : in out Unbounded_String);

   procedure Clear (Source : Unbounded_String);

...




      parent reply	other threads:[~1998-04-28  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-23  0:00 Variable-length arrays (from a C programmer) Paul T. McAlister
1998-04-24  0:00 ` Stephen Leake
1998-04-24  0:00 ` Anonymous
1998-04-24  0:00 ` Stephen Leake
1998-04-28  0:00 ` Matthew Heaney [this message]
replies disabled

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