comp.lang.ada
 help / color / mirror / Atom feed
* Re: Why doesn't an access to an imported C function work?
  1997-08-21  0:00 Why doesn't an access to an imported C function work? Matthew Kennedy
@ 1997-08-20  0:00 ` Robert Dewar
  0 siblings, 0 replies; 2+ messages in thread
From: Robert Dewar @ 1997-08-20  0:00 UTC (permalink / raw)



An access to subprogram value cannot point to subprograms with an
incompatible convention. The diagnostic from GNAT is:

    25.    Random := Random_Gaussian'Access;
                     |
        >>> subprogram has invalid convention for context

You need to use pragma Convention to specify the appropriate convention.





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

* Why doesn't an access to an imported C function work?
@ 1997-08-21  0:00 Matthew Kennedy
  1997-08-20  0:00 ` Robert Dewar
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Kennedy @ 1997-08-21  0:00 UTC (permalink / raw)



Hello, 

My appended sample program refuses to compile at the line where

  Random := Random_Gaussian'Access;

Where Random_Gaussian is a C function to be imported into Ada. I was
wondering wether Ada supported access to imported C functions (I know it
supports access to Ada function types) at all? 

It is important that the original C-source cannot be modified.

------------------------------------------------------------
with Ada.Float_Text_Io, Ada.Numerics, Text_Io, Interfaces.C;
use  Ada.Float_Text_Io, Ada.Numerics, Text_Io, Interfaces.C;

procedure Function_Access is

   function Random_Gaussian(X : in Double) return Double;
   function Random_Uniform(X : in Double) return Double;

   pragma Import(C, Random_Gaussian, "RandomGaussian");
   pragma Import(C, Random_Uniform, "RandomUniform");

   type Function_Access is access function (X: in Double ) return
Double;

   Random : Function_Access;

   procedure Evaluate(F : Function_Access; X : in Double; Y : out
Double) is
   begin
      Y := F(X);
   end Evaluate;

   X, Y : Double;

begin

   Random := Random_Gaussian'Access;

   X := 1.0;
   Y := Random(X);

--   Evaluate(F'Access, X, Y);
   Put(Item => X); New_Line;
   Put(Item => Y); New_Line;

end Function_Access;


-- 
Matthew Kennedy
Student of Electrical & Electronics Engineering
University of Southern Queensland, Australia




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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-08-21  0:00 Why doesn't an access to an imported C function work? Matthew Kennedy
1997-08-20  0:00 ` Robert Dewar

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