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!feeder.eternal-september.org!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Interfaces.C questions Date: Fri, 17 Mar 2017 23:57:58 +0200 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net bnKxy6EAZk3htdb1/SrfqwJdxuGc6Qg3LXlUHR2FMYIp0Kfb3o Cancel-Lock: sha1:NFZcylnzPbbSp1ctE5HoZJbsNzA= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:46414 Date: 2017-03-17T23:57:58+02:00 List-Id: On 17-03-17 23:12 , hreba wrote: > These are my first steps with Interfaces.C: > > ---------------------------------------------------------------------- > with Interfaces.C; > > package GSL is > > package C renames Interfaces.C; > > type size_t is new C.int; > type Real_Function is access function (x: C.double) return C.double; > > function Bessel_J0 (x: C.double) return C.double; > > function Integration_QNG > (f: Real_Function; > a, b, epsabs, epsrel: C.double; > result, abserr: out C.double; > neval: out size_t) > return C.int; > > private > > pragma Import (C, Bessel_J0, "gsl_sf_bessel_J0"); > pragma Import (C, Integration_QNG, "gsl_integration_qng"); > > end GSL; > ------------------------------------------------------------------------ > > No problem with function Bessel_J0. But Integration_QNG gets me: > > gsl.ads:19:07: functions can only have "in" parameters. > > The C prototype of this function is: > > int gsl_integration_qng (const gsl function * f , double a , double b , > double epsabs , double epsrel , double * result , double * abserr , size > t * neval ) > > So my questions are: > > 1. How do I translate C functions which return non-void and which > additionally use pointers for out parameters? Do I have to use pointers > in my Ada program? Using pointers is possible, but functions with "out" or "in out" parameters are allowed in the Ada 2012 standard. Check your compiler; it may by default use the Ada 2005 rules and may need a command-line option (perhaps -gnat2012) to use Ada 2012 rules. > 2. On my platform size_t is C.int. How can I define size_t in a > platform-independent way? Don't define it; use Interfaces.C.size_t. > 3. The C function above needs a pointer to a function as parameter. Is > my translation to Ada correct? Looks ok to me, but you didn't show the C prototype of the function (the gsl_function type?) so I can't compare the two. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .