comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Interfaces.C questions
Date: Sun, 19 Mar 2017 23:53:01 +0000
Date: 2017-03-19T23:53:01+00:00	[thread overview]
Message-ID: <lyziggddsy.fsf@pushface.org> (raw)
In-Reply-To: ej85m3F79k3U1@mid.individual.net

hreba <f_hreba@yahoo.com.br> writes:

> On 03/19/2017 08:22 PM, Simon Wright wrote:
>> hreba <f_hreba@yahoo.com.br> writes:
>>
>>>    function func (x: C.double; params: Void_Ptr) return C.double is
>>>    begin
>>>       return C.double (real_func (Real(x)));
>>>    end func;
>>>    pragma Convention (C, func);		-- this is line 37
>>
>> Try
>>
>>    function func (x: C.double; params: Void_Ptr) return C.double;
>>    pragma Convention (C, func);
>>    function func (x: C.double; params: Void_Ptr) return C.double is
>>    begin
>>       return C.double (real_func (Real(x)));
>>    end func;
>>
>> You have to have a spec, but there's nothing stopping it being declared
>> right before the body.
>>
>> Of course, in most cases you'd prefer to do that earlier.
>>
>
> Did that. Now I get:
>
> gsl.adb:35:26: pragma "CONVENTION" argument must be in same declarative part

This compiles for me (with a warning, 'variable "real_func" is read but
never assigned'):

generic
   type Real is digits <>;
   type Parameters is private;
package GSL with Elaborate_Body is
   type Real_Function is access function (x: Real) return Real;
end Gsl;
with Interfaces.C;
package body Gsl is

   use Interfaces;

   type Void_Ptr is access all Integer;
   pragma Convention (C, Void_Ptr);

   type GSL_Function is record
      func:   access
	function (x: C.double; params: Void_Ptr) return C.double;
      params: Void_Ptr;
   end record;
   pragma Convention (C, GSL_Function);

   real_func:	Real_Function;

   function func (x: C.double; params: Void_Ptr) return C.Double;
   pragma Convention (C, func);

   function func (x: C.double; params: Void_Ptr) return C.double is
   begin
      return C.double (real_func (Real(x)));
   end func;

   procedure P is
      gslf:	aliased GSL_Function;
   begin
      gslf.func:= func'Access;
   end P;
end Gsl;

  reply	other threads:[~2017-03-19 23:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-17 21:12 Interfaces.C questions hreba
2017-03-17 21:57 ` Niklas Holsti
2017-03-17 22:14 ` Jeffrey R. Carter
2017-03-17 22:24 ` Dmitry A. Kazakov
2017-03-21 21:08   ` Michael B.
2017-03-21 21:28     ` Dmitry A. Kazakov
2017-03-21 21:31     ` Simon Wright
2017-03-22 20:35       ` Randy Brukardt
2017-03-18 15:46 ` hreba
2017-03-18 16:26   ` Jeffrey R. Carter
2017-03-18 16:27   ` Jeffrey R. Carter
2017-03-19  7:03   ` Keith Thompson
2017-03-18 23:24 ` Leo Brewin
2017-03-19 12:17   ` hreba
2017-03-20  9:44     ` Leo Brewin
2017-03-19  7:00 ` Keith Thompson
2017-03-19 12:05 ` Per Sandberg
2017-03-19 18:39 ` hreba
2017-03-19 19:22   ` Simon Wright
2017-03-19 19:49     ` hreba
2017-03-19 23:53       ` Simon Wright [this message]
2017-03-20 11:12         ` hreba
2017-03-20 14:04         ` hreba
2017-03-22 11:21           ` hreba
replies disabled

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