(This post is related to two earlier posts by me, "Linking Ada to Pascal" and 'Where is documentation for "new argument to _p_initialize (@)" PCStrings.')
I have not been able to solve the problem when calling _p_initialize from Ada. I still get the Ada compiler telling me, "too many arguments in call." I suspect that I might be passing the wrong _kinds_ of arguments but not the wrong number.
Here are the three relevant files:
<file adacallspascal.adb> with Ada.Text_IO; use Ada.Text_IO; with Ada.Command_Line; use Ada.Command_Line; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure adacallspascal is
procedure mypascalprocedure; pragma Import(Convention => C, Entity => mypascalprocedure);
procedure init_pascal_main_program; pragma Import(Convention => C, Entity => init_pascal_main_program, External_Name => "_p__M0_init");
procedure p_initialize; pragma Import(Convention => C, Entity => p_initialize, External_Name => "_p_initialize");
procedure p_finalize; pragma Import(Convention => C, Entity => p_finalize, External_Name => "_p_finalize");
Argument_Count_Plus_1 : integer := Argument_Count + 1; Command_Name_String : string := Command_Name; C_Command_Name_String : aliased string := Command_Name_String & ASCII.NUL; begin Put_Line ("Hello from adacallspascal."); Put(Argument_Count_Plus_1); New_Line; Put_Line(Command_Name_String);
-- Initialize the Pascal RTS. p_initialize (Argument_Count_Plus_1, C_Command_Name_String'access, null, 0); -- Line 29
init_pascal_main_program; mypascalprocedure; p_finalize; Put_Line ("Goodbye from adacallspascal."); end adacallspascal;
<file mypascalprogram.pas> program mypascalprogram(input, output);
{$gpc-main=dummy}
procedure mypascalprocedure; attribute( name = 'mypascalprocedure'); begin writeln('Hello from mypascalprocedure.'); end;
begin {When exported to Ada, this part should not be called.} writeln('In mypascalprogram; error if calling from Ada.'); end.
<The commands> gpc -c mypascalprogram.pas gnatmake adacallspascal.adb -gnatf -largs mypascalprogram.o / Developer/Pascal/gpc344d2/lib/gcc/powerpc-apple-darwin8/3.4.4/libgpc.a
<Output from attempting to compile> gcc -c -gnatf adacallspascal.adb adacallspascal.adb:29:05: too many arguments in call gnatmake: "adacallspascal.adb" compilation error
Jerry