From: Jeffrey Carter <spam@spam.com>
Subject: Re: array of strings in a function
Date: Wed, 15 Oct 2003 03:08:23 GMT
Date: 2003-10-15T03:08:23+00:00 [thread overview]
Message-ID: <HS2jb.1451$7a4.817@newsread4.news.pas.earthlink.net> (raw)
In-Reply-To: <pan.2003.10.14.20.54.54.17088@atc.ugr.es>
Antonio Martï¿œnez wrote:
> I'm trying to pass to a function an argument. The argument is an
> array range <> of Strings (unbounded array).
>
> For example:
>
> my_fun("Hello", ", I'm", " the function");
This looks like a procedure, not a function.
> number of string literals is unknown by the function. And the
> length of every string is unknown as well.
>
> It works if I choose a fixed length of the string, and every string
> is exactly the length I have forced.
>
> So, if I fixed 4, it works for me:
> my_fun("only", "four", "lette", "rs ", "are ", "allo", "ed ");
You can't have a subprogram with an unknown number of parameters, which
is what you've been trying to write.
> How do I work with unbound strings?
>
> I want something like this:
>
> type Miarray is array (Positive range <>) of string;
>
> but it doen't compile !!!
Of course not. String is an indefinite type, and the components of an
array type must be definite. You say you want unbounded strings, so use
unbounded strings:
use Ada.Strings.Unbounded;
type Mine is array (Positive range <>) of Unbounded_String;
Then you can write
procedure Proc (Arg : in Mine);
and call it
Proc (Arg => (To_Unbounded_String ("Hello") ,
To_Unbounded_String (", I am"),
To_Unbounded_String (" Ada!") );
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
next prev parent reply other threads:[~2003-10-15 3:08 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-14 20:54 array of strings in a function Antonio Martínez
2003-10-15 2:55 ` Robert I. Eachus
2003-10-15 3:29 ` Jeff C,
2003-10-15 3:08 ` Jeffrey Carter [this message]
2003-10-16 6:40 ` tmoran
2003-10-16 9:31 ` Craig Carey
2003-10-16 18:13 ` Craig Carey
2003-10-16 21:44 ` Marius Amado Alves
2003-10-17 19:48 ` Craig Carey
2003-10-18 10:05 ` Marius Amado Alves
2003-10-18 20:05 ` Craig Carey
2003-10-30 9:42 ` Craig Carey
2003-10-16 17:58 ` Jeffrey Carter
2003-10-16 20:00 ` tmoran
2003-10-17 0:51 ` Jeffrey Carter
2003-10-15 11:49 ` Antonio Martínez Álvarez
2003-10-15 12:29 ` Preben Randhol
2003-10-15 14:19 ` Ole-Hjalmar Kristensen
2003-10-16 14:30 ` Robert I. Eachus
2003-10-16 17:53 ` Jeffrey Carter
2003-10-17 0:48 ` Robert I. Eachus
2003-10-17 18:41 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox