comp.lang.ada
 help / color / mirror / Atom feed
From: Tilman Gloetzner <Tilman.Gloetzner@uundz.de>
Subject: Q: Interfacing C/ADA: Indirect Calls
Date: Wed, 18 Apr 2001 14:54:25 +0200
Date: 2001-04-18T14:54:25+02:00	[thread overview]
Message-ID: <3ADD8E81.CE65B92A@uundz.de> (raw)

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 <stdio.h>
 
 
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;



             reply	other threads:[~2001-04-18 12:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-18 12:54 Tilman Gloetzner [this message]
2001-04-18 11:46 ` Q: Interfacing C/ADA: Indirect Calls Florian Weimer
2001-04-18 13:56   ` Tilman Glotzner
2001-04-18 14:53     ` Marin David Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox