-- interfex.adb use of interface packages -- built using commands: -- gcc -c interfex.adb -- gcc -c a_funct2.ads (not really needed here) -- gcc -c a_funct2.adb -- gcc -c c_funct2.c -- gnatbl interfex.ali a_funct2.o c_funct2.o -- interfex -- The output is: -- Interfex running -- I am now in C_Funct -- An integer is passed 5 -- A float is passed 7.3 -- A string is passed What -- now calling a_funct2(I) -- In A_Funct2 -- a_funct2 got integer 5 -- now returning 4.73 -- returned 4.73000000000000E+00 with Interfaces; with Interfaces.C; with Interfaces.C.Strings; with Interfaces.C.Pointers; with Text_IO; procedure InterfEx is -- rename to keep code below neater subtype Chars_Ptr is Interfaces.C.Strings.Chars_Ptr; function New_String(S : String) return Chars_Ptr renames Interfaces.C.Strings.New_String; -- an Ada specification must correspond to C function prototype function C_Funct2(I : Integer; F : Float; S : Chars_Ptr) return Long_Float; -- the Ada compiler must know what language calling convention and Ada name pragma Import (C, C_Funct2); -- optionally, -- pragma Import ( Convention => C, -- Entity => C_Funct2, -- External_Name => "c_funct2", -- Link_Name => "_c_funct2"); I : Integer := 5; F : Float := 7.3; S : String(1..4) := "What"; -- normal Ada string D : Long_Float; begin Text_IO.Put_Line("Interfex running"); D := C_Funct2(I, F, New_String(S)); -- C function produces output Text_IO.Put_Line("returned " & Long_Float'Image(D)); end InterfEx;