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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,454744523f134e53 X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: Help with access-to-functions and imported C functions Date: 1997/08/20 Message-ID: <33FB4226.384E@gsfc.nasa.gov>#1/1 X-Deja-AN: 265532573 References: <33F31D5B.71B2@mail.connect.usq.edu.au> Reply-To: Stephen.Leake@gsfc.nasa.gov Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA Newsgroups: comp.lang.ada Date: 1997-08-20T00:00:00+00:00 List-Id: 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