[fpc-pascal] Dynamic arrays in FP

Michalis Kamburelis michalis at camelot.homedns.org
Thu May 5 13:30:42 CEST 2005

Jilani Khaldi wrote:
> Hi All,
> I have written a little library in C (compiled in as a DLL) to use it in 
> Free Pascal and  Delphi applications. While the code (below) works with 
> Delphi (7), I get an Access Violation using FPC (1.98). Perhaps I am 
> missing something.
> Any hint? Thanks!
> program fpc_dll;
> uses
>  sysutils;
> type
> myarray = array of double;
> // if I declare "myarray = array[0..9] of double;" the code runs as 
> expected.
> function get_array(a, b: myarray; size: integer; value: double): 
> integer; cdecl; external 'mylib.dll';

Change this to

   PDouble = ^Double;

function get_array(a, b: PDouble; size: integer; value: double): 
integer; cdecl; external 'mylib.dll';

In C "double a[]" is the same as "double *a" which is the same as "A: 
PDouble" in Pascal. "array of Double" is not the same thing as 
"PDouble", as fpc developers already explained.

> // extern "C"  __cdecl __declspec(dllexport) int get_array(double a[], 
> double b[], int size, double val);
>  qq := get_array(mat1,mat2,kk,3.14);

Change this to

qq := get_array(PDouble(mat1),PDouble(mat2),kk,3.14);


More information about the fpc-pascal mailing list