comp.lang.ada
 help / color / mirror / Atom feed
* Q: Interfacing C/ADA: Indirect Calls
@ 2001-04-18 12:54 Tilman Gloetzner
  2001-04-18 11:46 ` Florian Weimer
  0 siblings, 1 reply; 4+ messages in thread
From: Tilman Gloetzner @ 2001-04-18 12:54 UTC (permalink / 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;



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-04-18 14:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-18 12:54 Q: Interfacing C/ADA: Indirect Calls Tilman Gloetzner
2001-04-18 11:46 ` Florian Weimer
2001-04-18 13:56   ` Tilman Glotzner
2001-04-18 14:53     ` Marin David Condic

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