From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Help with access-to-functions and imported C functions
Date: 1997/08/20
Date: 1997-08-20T00:00:00+00:00 [thread overview]
Message-ID: <33FB4226.384E@gsfc.nasa.gov> (raw)
In-Reply-To: 33F31D5B.71B2@mail.connect.usq.edu.au
Matthew Kennedy wrote:
>
> ...
>
> It seems how ever, that I cannot assign the access of an imported C
> function (please see code below for the exact error message) to an
> access variable of the same 'type' of function.
>
> ...
> Random := Random_Gaussian'Access; -- gives compile error
> "subprogram has invalid convention for context"
>
As this message is (somewhat cryptically) trying to tell you, you have
specified different calling conventions for Random and Random_Gaussian.
You need to use "pragma Convention". Note that you must apply the pragma
to both the access type, and the function "Two":
with Ada.Text_IO, Interfaces.C;
use Ada.Text_IO, Interfaces.C;
procedure Test
is
package Double_IO is new Ada.Text_IO.Float_IO(Double);
use Double_IO;
type Function_Access is access function return Double;
pragma Convention (C, Function_Access);
function Random_Gaussian return Double; -- double
RandomGaussian(void);
function Random_Uniform return Double; -- double
RandomUniform(void);
pragma Import(C, Random_Gaussian, "RandomGaussian");
pragma Import(C, Random_Uniform, "RandomUniform");
function Two return Double;
pragma Convention (C, Two);
function Two return Double is
begin
return 2.0;
end Two;
Random : Function_Access;
Y : Double;
begin
Random := Two'Access;
Random := Random_Gaussian'Access;
Y := Random.all;
Put(Y);
New_Line;
end Test;
> --
> Matthew Kennedy
> Student of Electronics Engineering
> University of Southern Queensland, Australia
> "When will you realise your already there?"
> - Marilyn Manson
--
- Stephe
prev parent reply other threads:[~1997-08-20 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-08-15 0:00 Help with access-to-functions and imported C functions Matthew Kennedy
1997-08-20 0:00 ` Stephen Leake [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