Board index » delphi » Help with command-line args in GNU Pascal

Help with command-line args in GNU Pascal

I want to use C functions in GNU Pascal, which want argc and argv passed.I
tried to emulate these variables, but everytime I tried, I got a coredump or
bus error. Is there somebody knowing to pass arguements from Pascal to C
functions? By the way, declaration of C Functions in GNU Pascal is like

        (for int foo(int i) )
        function foo(i:integer):integer;C_Language;
Thanks in advance,

-Turan Yuksel (e1097...@ceng.metu.edu.tr)

 

Re:Help with command-line args in GNU Pascal


Quote
turan yuksel (advis...@rorqual.cc.metu.edu.tr) wrote:
> I want to use C functions in GNU Pascal, which want argc and argv passed.I
> tried to emulate these variables, but everytime I tried, I got a coredump or
> bus error. Is there somebody knowing to pass arguements from Pascal to C
> functions?

There should be no problems passing arguments from GNU Pascal to a
32-bit C.  Let the C function be

    int foo ( int argc, char **argv );

then the equivalent GNU Pascal declaration is

    Function Foo ( ArgC: Integer; Var ArgV: array of CString ); C;

(If you are using an older version of GNU Pascal, it might be `__CString__'
instead of `CString'.)

Please make sure that `int' is 32 bit in your C, and that you didn't
forget the `Var' above.

BTW, to access command-line arguments from GNU Pascal, the following gives
you Borland-compatible `ParamCount' and `ParamStr' functions:

    Type
      WrkString = String ( 255 );

    Function rtsParamCount: Integer;
    AsmName '_p_paramcount';

    Function rtsParamStr ( i: Integer; Var S: String ): Boolean;
    AsmName '_p_paramstr';

    Function ParamCount: Integer;

    begin (* ParamCount *)
      ParamCount:= rtsParamCount - 1;
    end (* ParamCount *);

    Function ParamStr ( i: Integer ): WrkString;

    Var
      S: String ( 255 );

    begin (* ParamStr *)
      if rtsParamStr ( i, S ) then
        ParamStr:= Trim ( S )
      else
        ParamStr:= '';
    end (* ParamStr *);

Hope this helps,

    Peter

 Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
Reply e-mail to "uni-essen"   http://home.pages.de/~peter.gerwinski/ [970201]
instead of "NO-SPAM-PLEASE".  maintainer GNU Pascal [970510] kampi.hut.fi/gpc
Sorry for the inconvenience.  http://home.pages.de/~gnu-pascal/ [970125]

Other Threads