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=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ef14853fdea3d0ea,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-18 03:56:06 PST Path: supernews.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.ems.psu.edu!news.cis.ohio-state.edu!news.maxwell.syr.edu!grolier!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: Tilman Gloetzner Newsgroups: comp.lang.ada Subject: Q: Interfacing C/ADA: Indirect Calls Date: Wed, 18 Apr 2001 14:54:25 +0200 Organization: T-Online Message-ID: <3ADD8E81.CE65B92A@uundz.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.t-online.com 987591266 06 9638 FdTVSm-TSUYAlm 010418 10:54:26 X-Complaints-To: abuse@t-online.com X-Sender: 0931406720-0001@t-dialin.net X-Mailer: Mozilla 4.76 [de] (X11; U; Linux 2.4.0-64GB-SMP i686) X-Accept-Language: en Xref: supernews.google.com comp.lang.ada:6967 Date: 2001-04-18T14:54:25+02:00 List-Id: Hello, here comes another question concerning Ada interfacing C. The idea is to call 2 C-functions inidrectly from an Ada program. The test program I wrote does not compile (I am using gnat running on linux): gnatmake -c use_indirect.adb -o use_indirect.o gcc -c use_indirect.adb use_indirect.adb:10:08: subprogram has invalid convention for context use_indirect.adb:16:08: subprogram has invalid convention for context gnatmake: "use_indirect.adb" compilation error make: *** [use_indirect.o] Error 4 The user guide nor the reference manual seem not to explicitly cover this (at least I did not find anything about indirect calls to code in other languages). Thanks in anticipation, Tilman ======================================================================== /* C procedures */ #include int function1(int p1,int p2) { return(p1+p2); } int function2(int p1, int p2) { return(p1*p2); } -- --------------- pacakage ind_call ----------------- with Interfaces.C;use Interfaces.C; package ind_call is type Indirect_Func is access function(param_1 : in Int; param_2 : in Int) return Int; function C_Function1(p1: in Int; p2: in Int) return Int; function C_Function2(p1: in Int; p2: in Int) return Int; pragma Import(C,C_Function1,"function1"); pragma Import(C,C_Function2,"function2"); end ind_call; ----------- "main" program ----------------- with TEXT_IO;use TEXT_io; with Interfaces.C; use Interfaces.C; with ind_call;use ind_call; procedure use_indirect is package Int_io is new INTEGER_IO(Int); f1: Indirect_Func; I: Int; begin f1 := C_Function1'Access; -- this does not compile I := f1(2,3); Text_io.Put("Function1 = "); Int_io.Put(I); New_line; f1 := C_Function2'Access; -- this does not compile I := f1(2,3); Text_io.Put("Function2 = "); Int_io.Put(I); New_line; end use_indirect;