From: "Samuel A. Mize" <smize@magellan.bgm.link.com>
Subject: Re: Export in generic packages
Date: 1997/05/19
Date: 1997-05-19T00:00:00+00:00 [thread overview]
Message-ID: <3380BC29.41C6@magellan.bgm.link.com> (raw)
In-Reply-To: 5lpm7e$gq7$1@luna.ffi.no
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
prev parent reply other threads:[~1997-05-19 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-05-19 0:00 Export in generic packages Rune Wemberg
1997-05-19 0:00 ` Samuel A. Mize [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox