comp.lang.ada
 help / color / mirror / Atom feed
* Pragma Import to C "Accept" function?
@ 1997-02-12  0:00 Al Priest
  1997-02-12  0:00 ` Samuel Tardieu
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Al Priest @ 1997-02-12  0:00 UTC (permalink / raw)



I'm looking for a "nice" way to interface to the C accept function. Given
it's clash with the reserved word accept, is there a good way to interface
to the function? Currently the only way I can do it is by writing a C
function to interface to the accept, and then interfacing to that in my
Ada program.

I'm using latest (Jan'97) version of Gnat compiler for Linux in case it
matters.

Thanks,

Al
--
al@priest.com




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Pragma Import to C "Accept" function?
  1997-02-12  0:00 Pragma Import to C "Accept" function? Al Priest
@ 1997-02-12  0:00 ` Samuel Tardieu
  1997-02-13  0:00 ` Do-While Jones
  1997-02-24  0:00 ` Robert Dewar
  2 siblings, 0 replies; 6+ messages in thread
From: Samuel Tardieu @ 1997-02-12  0:00 UTC (permalink / raw)
  To: Al Priest


>>>>> "Al" == Al Priest <cm3bcawp@bs47c.staffs.ac.uk> writes:

Al> I'm looking for a "nice" way to interface to the C accept
Al> function. Given it's clash with the reserved word accept, is there
Al> a good way to interface to the function? Currently the only way I
Al> can do it is by writing a C function to interface to the accept,
Al> and then interfacing to that in my Ada program.

I cannot see the point here. You can perfectly interface with C
functions which have the same name than an Ada keyword. You do not
*have to* give the same name than the C function, just use a third
parameter to the pragma Import to give the external name.

In your case, what you could do is:

  function C_Accept (<params>) return Interfaces.C.int;
  pragma Import (C, C_Accept, "accept");

Hope this helps.

  Sam
-- 
Samuel Tardieu -- sam@ada.eu.org




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Pragma Import to C "Accept" function?
  1997-02-12  0:00 Pragma Import to C "Accept" function? Al Priest
  1997-02-12  0:00 ` Samuel Tardieu
@ 1997-02-13  0:00 ` Do-While Jones
  1997-02-20  0:00   ` Samuel Mize
  1997-02-24  0:00 ` Robert Dewar
  2 siblings, 1 reply; 6+ messages in thread
From: Do-While Jones @ 1997-02-13  0:00 UTC (permalink / raw)



In article <5ds893$qgf@bs33n.staffs.ac.uk> cm3bcawp@bs47c.staffs.ac.uk (Al Priest) writes:
>I'm looking for a "nice" way to interface to the C accept function. Given
>it's clash with the reserved word accept, is there a good way to interface
>to the function? Currently the only way I can do it is by writing a C
>function to interface to the accept, and then interfacing to that in my
>Ada program.
>
>I'm using latest (Jan'97) version of Gnat compiler for Linux in case it
>matters.
>
>Thanks,
>
>Al
>--
>al@priest.com

Here's how I do it.

(I don't normally use lower case for function names and variable names, 
but I did here because I was matching the C names.)

function accept_connection(
  socket  : in Socket_numbers;
  addr    : in SYSTEM.Address;
  addrlen : in SYSTEM.Address)
  return Socket_numbers;
pragma Interface (C, accept_connection);
pragma Interface_Information
  (accept_connection, "_accept");

The code above works for Telesoft Telegen 2 on a Sun workstation.  To 
make it run on Verdix on a Silicon Graphic machine I had to change the 
last pragma to

pragma Interface_Name
  (accept_connection, "accept");

Both versions of this interface have run for years without problems.

Do-While Jones

-- 
            +--------------------------------+
            |    Know                 Ada    |
            |        [Ada's Portrait]        |
            |    Will              Travel    |
            | wire do_while@ridgecrest.ca.us |
            +--------------------------------+




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Pragma Import to C "Accept" function?
  1997-02-13  0:00 ` Do-While Jones
@ 1997-02-20  0:00   ` Samuel Mize
  0 siblings, 0 replies; 6+ messages in thread
From: Samuel Mize @ 1997-02-20  0:00 UTC (permalink / raw)



In article <5dv9kc$3sr@ash.ridgecrest.ca.us>,
Do-While Jones <do_while@lo-pan.ridgecrest.ca.us> wrote:

>In article <5ds893$qgf@bs33n.staffs.ac.uk> cm3bcawp@bs47c.staffs.ac.uk
(Al Priest) writes:
>>I'm looking for a "nice" way to interface to the C accept function. Given
>>it's clash with the reserved word accept, is there a good way to interface
>>to the function?
 
and answered, correctly for Ada 83, with Telesoft Telegen 2 on a Sun:
 
>function accept_connection(
>  socket  : in Socket_numbers;
>  addr    : in SYSTEM.Address;
>  addrlen : in SYSTEM.Address)
>  return Socket_numbers;
>pragma Interface (C, accept_connection);
>pragma Interface_Information
>  (accept_connection, "_accept");
 
or on Verdix/SGI:
 
>pragma Interface_Name
>  (accept_connection, "accept");
 
These pragmas are vendor-specific.  In Ada95, the pragma Export is
available, which combines the functions of Interface and Interface_Name
(or Interface_Information).

>>I'm using latest (Jan'97) version of Gnat compiler for Linux in case it
>>matters.

It matters.  Unless you're using the -gnat83 switch, you have Ada95, so
you can use pragma Export.

Samuel Mize











^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Pragma Import to C "Accept" function?
  1997-02-12  0:00 Pragma Import to C "Accept" function? Al Priest
  1997-02-12  0:00 ` Samuel Tardieu
  1997-02-13  0:00 ` Do-While Jones
@ 1997-02-24  0:00 ` Robert Dewar
  1997-03-04  0:00   ` Al Priest
  2 siblings, 1 reply; 6+ messages in thread
From: Robert Dewar @ 1997-02-24  0:00 UTC (permalink / raw)



Al Priest asks

<<I'm looking for a "nice" way to interface to the C accept function. Given
it's clash with the reserved word accept, is there a good way to interface
to the function? Currently the only way I can do it is by writing a C
function to interface to the accept, and then interfacing to that in my
Ada program.>>

No one ever said you must use the same name on the Ada side as on the
C side. It is often nice to do so, but there are many cases where it
is not possible (in addition to the reserved word case, consider
names like _____hello and cases where Hello and hello are different
functions).

You just write

  pragma Import (C, Ada_Name_Of_Function, "C_Name_Of_Function");

e.g. for your case:

  pragma Import (C, C_Accept, "accept");

or somesuch. It would be helpful if you could track down why you had a
misunderstanding here so that whatever text you are using can be clarified.
The RM itself seems clear on this point.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Pragma Import to C "Accept" function?
  1997-02-24  0:00 ` Robert Dewar
@ 1997-03-04  0:00   ` Al Priest
  0 siblings, 0 replies; 6+ messages in thread
From: Al Priest @ 1997-03-04  0:00 UTC (permalink / raw)



Robert Dewar said:
> Al Priest asks

> <<I'm looking for a "nice" way to interface to the C accept function. Given
> it's clash with the reserved word accept, is there a good way to interface
> to the function? Currently the only way I can do it is by writing a C
> function to interface to the accept, and then interfacing to that in my
> Ada program.>>

> No one ever said you must use the same name on the Ada side as on the
> C side. It is often nice to do so, but there are many cases where it
> is not possible (in addition to the reserved word case, consider
> names like _____hello and cases where Hello and hello are different
> functions).

> You just write

>   pragma Import (C, Ada_Name_Of_Function, "C_Name_Of_Function");

> e.g. for your case:

>   pragma Import (C, C_Accept, "accept");

> or somesuch. It would be helpful if you could track down why you had a
> misunderstanding here so that whatever text you are using can be clarified.
> The RM itself seems clear on this point.


Thanks for all the help on this subject, it's working fine now. The reason
the confusion started was that I was using an Ada83 RM, and so no mention
of this technique.

Al
--
al@priest.com




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1997-03-04  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-12  0:00 Pragma Import to C "Accept" function? Al Priest
1997-02-12  0:00 ` Samuel Tardieu
1997-02-13  0:00 ` Do-While Jones
1997-02-20  0:00   ` Samuel Mize
1997-02-24  0:00 ` Robert Dewar
1997-03-04  0:00   ` Al Priest

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