From: Craig Carey <research@ijs.co.nz>
Subject: Re: array of strings in a function
Date: Thu, 16 Oct 2003 22:31:23 +1300
Date: 2003-10-16T22:31:23+13:00 [thread overview]
Message-ID: <8unsov8a3r9p02lm0ftkmmget77esc7fv7@4ax.com> (raw)
In-Reply-To: u3rjb.783826$Ho3.210237@sccrnsc03
Functions with varying numbers of arguments are handled by Ada 95:
construct an array of pointers at the place the procedure is called:
-----
with Text_IO;
with Ada.Unchecked_Deallocation;
procedure Main is
type String_Ptr is access all String;
type SPA is array (Positive range <>) of String_Ptr;
procedure Deallocate is new Ada.Unchecked_Deallocation (
Object => String, Name => String_Ptr);
function "+" (X : String) return String_Ptr is
begin
return new String'(X);
end "+";
procedure Varargs (U : SPA) is
Tmp : String_Ptr;
begin
Text_IO.Put ("Got : ");
for K in U'Range loop
Text_IO.Put ("""" & String (U (K).all) & """");
if K /= U'Last then Text_IO.Put (", "); end if;
Tmp := U (K);
Deallocate (Tmp); -- No memory leak
end loop;
Text_IO.Put_Line (".");
end Varargs;
G : String := "Efgh";
begin
Varargs (SPA'(1 => +"Abc", 2 => +G, 3 => +"Last"));
end Main
-----
The output:
| Got : "Abc", "Efgh", "Last".
Syntax errors are a problm when the heap is not used (a GNAT pointer to
a string is 64 bits and twice the size of a pointer to a record).
On Thu, 16 Oct 2003 06:40:26 GMT, tmoran@acm.org wrote:
...
> But you can certainly have a set of subprograms with the same name
>but differing number of parameters:
...
At Wed, 15 Oct 2003 13:49:42 +0200, Antonio Mart�nez wrote:
Subject: Re: array of strings in a function
[from comp.lang.ada-@-ada-france.org ]
>What I want to do is a procedure (sorry, not a function) to do something
>like this:
>
>my_AND("Entrada_1", "P2", "Output");
>
>and with this argument, this function have to write this:
>
>
>entity my_AND is port(
> Entrada_1 : in std_logic;
> P2 : in std_logic;
> Output : out std:logic;
>);
>
>(This is VHDL code, very similar to Ada95).
>
> In general, I don't know the number of string arguments.
...
Is that a parser project?.
Adagoop and Ayacc are options:
ftp://ftp.usafa.af.mil/pub/dfcs/carlisle/usafa/adagoop/index.html
http://www.mysunrise.ch/users/gdm/gsoft.htm
-- Craig Carey
next prev parent reply other threads:[~2003-10-16 9:31 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
2003-10-16 6:40 ` tmoran
2003-10-16 9:31 ` Craig Carey [this message]
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