comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Importing a Unix function call
Date: 1998/12/06
Date: 1998-12-06T00:00:00+00:00	[thread overview]
Message-ID: <m33e6t7hqk.fsf@mheaney.ni.net> (raw)
In-Reply-To: 36683FA3.2512DECF@ndirect.co.uk

Steve Crowe <stevecrowe@ndirect.co.uk> writes:

> GNAT AdA compiler running under Unix, the function being imported is a
> Unix 'pipe'.

From my man page:

       int pipe(int filedes[2]);

       pipe  creates  a  pair  of file descriptors, pointing to a
       pipe inode, and places them in the  array  pointed  to  by
       filedes.   filedes[0]  is  for  reading, filedes[1] is for
       writing.


C doesn't have out parameters: only in parameters that point to the
return data.

How about something like:

with Interfaces.C;  use Interfaces;
package UNIX is

  type File_Descriptor is new C.int;

  type File_Descriptor_Array is
     array (Positive range 1 .. 2) of File_Descriptor;

  pragma Convention (C, File_Descriptor_Array);

  type File_Descriptor_Array_Access is
     access all File_Descriptor_Array;

  pragma Convention (C, File_Descriptor_Array_Access);

  function Pipe
    (Files : in File_Descriptor_Array_Access)
     return C.Int;

  pragma Import (C, Pipe);

end UNIX;


You'd use it like:

declare
  Files  : alised File_Descriptor_Array;
  Status : constant C.Int := Pipe (Files'Access);
begin
...


Is that what you had in mind?

  





  parent reply	other threads:[~1998-12-06  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-04  0:00 Importing a Unix function call Steve Crowe
1998-12-04  0:00 ` Larry Kilgallen
1998-12-04  0:00   ` David Botton
1998-12-05  0:00     ` Larry Kilgallen
1998-12-04  0:00 ` dennison
1998-12-06  0:00 ` Matthew Heaney [this message]
1998-12-06  0:00   ` David Botton
1998-12-06  0:00     ` Matthew Heaney
1998-12-07  0:00       ` dennison
replies disabled

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