The Ada Program: main.adb
1 with Interfaces.C; use Interfaces;
2 with Ada.Text_IO; use Ada;
3
4 procedure Main is
5
6 function My_C_Fun (X: C.int) return C.int;
7 -- The function is called "fun" in C.
8 pragma Import (C, My_C_Fun, "fun");
9 -- The function "fun" is found in the object file "c_progs.o"
10 pragma Linker_Options ("c_progs.o");
11
12 -- For convenience we write a wrapper function
13 function My_Fun (X: Integer) return Integer is
14 begin
15 return (Integer(My_C_Fun (C.int(X))));
16 end My_Fun;
17
18 begin
19
20 Text_IO.Put_Line (Integer'Image (My_Fun (4)));
21
22 end Main;