From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Exec shell command with GNAT
Date: Tue, 14 Jan 2003 06:15:21 -0600
Date: 2003-01-14T06:15:21-06:00 [thread overview]
Message-ID: <mailman.1042546681.15298.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: MPG.188def7c97db9f32989698@news.ip-plus.net
----- Original Message -----
From: "Thomas Wolf" <t_wolf@angelfire.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: January 14, 2003 2:58 AM
Subject: Re: Exec shell command with GNAT
> david.c.hoos.sr@ada95.com wrote:
> > with Ada.Characters.Latin_1;
> > with System;
> > function Execute_Shell_Command
> > (The_Command : String) return Integer is
> >
> > function Execute
> > (The_Command_Address : System.Address) return Integer;
> > pragma Import (C, Execute, "system");
> > The_Nul_Terminated_Command_String : constant String :=
> > The_Command & Ada.Characters.Latin_1.Nul;
> > begin
> > return Execute (The_Nul_Terminated_Command_String'Address);
> > end Execute_Shell_Command;
>
> Yes, that's it. My own version looks similar:
>
> with Interfaces.C;
>
> function Execute (Command : in String) return Integer
> is
>
> function Run (Command : in Interfaces.C.char_array)
> return Interfaces.C.int;
> pragma Import (C, Run, "system");
>
> begin -- Execute
> return Integer (Run (Interfaces.C.To_C (Item => Command)));
> end Execute;
>
> No fiddling around with addresses needed, and the declaration of "Run"
> doesn't depend on Interfaces.C.int and Integer being the same. Note
> that the Ada standard guarantees that an in-parameter of an array of
> some element_type is passed in a way compatible with an "element_type *"
> in C. (I.e., the address of the first element is passed.)
I agree. I failed to mention that my function was originally written
before Ada95 existed. It's a case of "if it's not broken, don't 'fix'
it."
>
> --
> -----------------------------------------------------------------
> Thomas Wolf e-mail: t_wolf@angelfire.com
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>
next prev parent reply other threads:[~2003-01-14 12:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-13 16:58 Exec shell command with GNAT JuK
2003-01-13 17:59 ` David C. Hoos
2003-01-14 8:58 ` Thomas Wolf
2003-01-14 12:15 ` David C. Hoos, Sr. [this message]
2003-01-14 15:41 ` Adrian Knoth
2003-01-14 10:34 ` Lutz Donnerhacke
2003-01-13 18:52 ` Per Sandbergs
2003-01-13 19:01 ` 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