From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Interfaces.C questions Date: Sun, 19 Mar 2017 23:53:01 +0000 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9d1255fe3bfd76f1b16fb83b93d1fcf5"; logging-data="9264"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19INADHrP1aZe9M089CShgsJ+SauUPSmxU=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (darwin) Cancel-Lock: sha1:KzZUhSO2qNH3rhiIdhMdvyvXRNI= sha1:OG5yeilReUU+d3lNRf7OfH1vpgM= Xref: news.eternal-september.org comp.lang.ada:46428 Date: 2017-03-19T23:53:01+00:00 List-Id: hreba writes: > On 03/19/2017 08:22 PM, Simon Wright wrote: >> hreba 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;