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=2.1 required=5.0 tests=BAYES_40,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,start X-Google-Attributes: gid103376,public From: Matthew Kennedy Subject: Help with access-to-functions and imported C functions Date: 1997/08/15 Message-ID: <33F31D5B.71B2@mail.connect.usq.edu.au>#1/1 X-Deja-AN: 264181567 Reply-To: q957722@mail.connect.usq.edu.au Organization: University of Southern Queensland Newsgroups: comp.lang.ada Date: 1997-08-15T00:00:00+00:00 List-Id: Hello, I have this program which must sample either a Gaussian or a uniform random distribution. The functions to return the random numbers for each distribution are already defined in a file called random.c which has been compiled into random.o ready to link into my Ada program. I need the program to use either the Uniform or Gaussian functions depending on some user input at run-time so I tried to create a variable which is an access to a type of the same type as the C functions. 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. Doesn't Ada support such constructs? (I couldn't find the answer in the ARM) (Note the program below is just a representitive illustration of the actual problem) Thank you, Matt. with Ada.Text_IO, Interfaces.C; use Ada.Text_IO, Interfaces.C; -- COMPILE COMMAND: -- gcc -c random.c -o random.o -- gnatmake distribution -largs random.o procedure Distribution is package Double_IO is new Ada.Text_IO.Float_IO(Double); use Double_IO; type Function_Access is access function return Double; 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 is begin return 2.0; end Two; Random : Function_Access; Y : Double; begin Random := Two'Access; -- this line works, but the following line Random := Random_Gaussian'Access; -- gives compile error "subprogram has invalid convention for context" Y := Random.all; Put(Y); New_Line; end Distribution; -- Matthew Kennedy Student of Electronics Engineering University of Southern Queensland, Australia "When will you realise your already there?" - Marilyn Manson