comp.lang.ada
 help / color / mirror / Atom feed
* Export in generic packages
@ 1997-05-19  0:00 Rune Wemberg
  1997-05-19  0:00 ` Samuel A. Mize
  0 siblings, 1 reply; 2+ messages in thread
From: Rune Wemberg @ 1997-05-19  0:00 UTC (permalink / raw)




Hello!

I am trying to use the pragma Export in a generic
package for exporting an Ada procedure to C. The
gnatcompiler give me the message:

"internal entity cannot be exported"

The source looks like this:

generic
  -- Something here... 
package Generic_Pack

  procedure My_Proc(Item : in Float ;
                    AnotherItem : out Float ;
                    ThirdItem   : out Float) ;
  pragma Export(C, My_Proc, "my_proc");

end Generic_Pack;

If I try to use pragma Export outside the generic
package, I get the message:

"pragma EXPORT argument must be in same declarative part"

Is it not possible to export procedures from generic packages,
or instantions of theese?

-- 
Rune Wemberg
ruw@ffi.no




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

* Re: Export in generic packages
  1997-05-19  0:00 Export in generic packages Rune Wemberg
@ 1997-05-19  0:00 ` Samuel A. Mize
  0 siblings, 0 replies; 2+ messages in thread
From: Samuel A. Mize @ 1997-05-19  0:00 UTC (permalink / raw)



Rune Wemberg wrote:
> I am trying to use the pragma Export in a generic
> package for exporting an Ada procedure to C.

Been there, done that, it's a minor pain.

Use the "Convention" pragma so your generic procedure can be
properly called by C.

GNAT requires an exported procedure to be an externally visible
procedure of a library-level package.  So, you will define a
library-level package that exports the procedure.  Instantiate
the generic in that package, and use a renaming-as-body to
make the exported procedure equivalent to the instantiation.

Here's a concrete example, that compiles and links with GNAT.


-- export_me.ads --
generic
function Export_Me return integer;
pragma Convention (C, Export_Me);

-- export_me.adb --
function Export_Me return integer is
begin
   return 1776;
end Export_Me;


-- exporter.ads --
package Exporter is
   function C_Export_Me return integer;
   pragma Export (C, C_Export_Me, "export_me");
end Exporter;


-- exporter.adb --
with Export_Me;
package body Exporter is
   function Export_This_One is new Export_Me;
   function C_Export_Me return integer renames Export_This_One;
end Exporter;


/* import_it.c */
#include <stdio.h>
extern int export_me();
int main ()
{ printf ("%d\n", export_me()); }


Now:
  % gcc -c importer.adb
  % gcc import_it.c exporter.o -o import_it
  % import_it
  1776

Samuel Mize


Rune Wemberg wrote:
> 
> Hello!
> 
> I am trying to use the pragma Export in a generic
> package for exporting an Ada procedure to C. The
> gnatcompiler give me the message:
> 
> "internal entity cannot be exported"
> 
> The source looks like this:
> 
> generic
>   -- Something here...
> package Generic_Pack
> 
>   procedure My_Proc(Item : in Float ;
>                     AnotherItem : out Float ;
>                     ThirdItem   : out Float) ;
>   pragma Export(C, My_Proc, "my_proc");
> 
> end Generic_Pack;
> 
> If I try to use pragma Export outside the generic
> package, I get the message:
> 
> "pragma EXPORT argument must be in same declarative part"
> 
> Is it not possible to export procedures from generic packages,
> or instantions of theese?
> 
> --
> Rune Wemberg
> ruw@ffi.no


-- Samuel Mize           (817) 619-8622               "Team Ada"
-- Hughes Training Inc.  PO Box 6171 m/s 400, Arlington TX 76005




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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-19  0:00 Export in generic packages Rune Wemberg
1997-05-19  0:00 ` Samuel A. Mize

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