user15552120
user15552120

Reputation:

How to export instantiated generic function to C

I create a generic function with Export and Convention aspects. Then I instantiated this function, but it ends up in my library with the 'r' suffix. Why this happens and how can I fix this?

For example:

generic
   I : int;
function Test_Generic return int
   with Export => True, Convention => C;

function Test_Generic return int is
begin
   return I;
end;

function Test is new Test_Generic (I => 5);
-- In library this function has name testr

Upvotes: 2

Views: 86

Answers (2)

Niklas Holsti
Niklas Holsti

Reputation: 2142

A simpler answer is to move all aspects to the generic instance, but also add an External_Name aspect:

function Test is new Test_Generic (I => 5)
with Export, Convention => C, External_Name => "test";

I don't understand why External_Name is required here, and Export is not enough.

Upvotes: 4

Niklas Holsti
Niklas Holsti

Reputation: 2142

I have not been able to solve the problem fully, but here is a work-around, by moving the External and Convention aspects to a wrapper around the generic instance:

generic
   I : int;
function Test_Generic return int;

function Test_Generic return int is
begin
   return I;
end;

function Test_G is new Test_Generic (I => 5);

function Test return int
with Export, Convention => C;

function Test return int
is begin return Test_G; end Test;

It is a bit cumbersome, but seems to work.

Upvotes: 2

Related Questions