comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Array of Strings
Date: Sat, 13 Sep 2008 16:32:54 +0200
Date: 2008-09-13T16:32:54+02:00	[thread overview]
Message-ID: <87hc8kjeuh.fsf@ludovic-brenta.org> (raw)
In-Reply-To: fda9aa48-6029-469e-82fb-20bb99d750c6@73g2000hsx.googlegroups.com

jedivaughn <jedivaughn14@gmail.com> writes:
> Hi everyone,
>
> I'm having trouble making a array of type string. can some one show me
> how to do this. I've tried type letters is array (Integer range <>) of
> String; but I get error "unconstrained element type in array
> declaration". what am I doing wrong?

The type String is unconstrained because you don't know the size of
the strings at compile time.  Therefore you cannot put Strings in an
array.  You can however create:

- an array of fixed-size strings; for this you need a subtype e.g.

subtype Constrained_String is String (1 .. 10);
type Array_Of_Constrained_Strings is
  array (Positive range <>) of Constrained_String;

- an array of access values to Strings e.g.

type String_Access is access String;
type Array_Of_String_Accesses is array (Positive range <>) of String_Access;

(!this is the most error-prone method!)

- an array of Ada.Strings.Unbounded.Unbounded_Strings e.g.

type Array_Of_Unbouded_Strings is
  array (Positive range <>) of Ada.Strings.Unbounded.Unbounded_String;

- an array of Ada.Strings.Bounded.Bounded_Strings similar to the above
  but you also need to specify the maximum size

HTH

-- 
Ludovic Brenta.



  reply	other threads:[~2008-09-13 14:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-13 14:18 Array of Strings jedivaughn
2008-09-13 14:32 ` Ludovic Brenta [this message]
2008-09-14  0:11 ` anon
2008-09-14  9:45 ` Per Sandberg
2008-09-15 14:54 ` Adam Beneschan
2008-09-16 23:56   ` jedivaughn
2008-09-23 14:07     ` jedivaughn
2008-09-23 14:30       ` mockturtle
2008-09-23 14:41         ` Adam Beneschan
2008-09-23 14:47         ` Ludovic Brenta
2008-09-23 18:51       ` Jeffrey R. Carter
2008-09-24 12:00         ` jedivaughn
2008-09-24 14:36           ` Adam Beneschan
2008-09-24 15:13           ` John McCormick
2008-09-24 17:18           ` Jeffrey R. Carter
2008-09-28 12:24             ` jedivaughn
2008-09-28 13:01               ` mockturtle
2008-09-28 17:08                 ` jedivaughn
2008-09-29 11:14                   ` mockturtle
2008-09-28 19:00               ` Jeffrey R. Carter
2008-09-29 15:51                 ` Adam Beneschan
replies disabled

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