[fpc-pascal] Pass open array to static array?

Howard Page-Clark hdpc at talktalk.net
Sun Mar 15 14:53:21 CET 2020


On 15/03/2020 12:06, Ryan Joseph via fpc-pascal wrote:
> program test;
> var
>    data: array[0..2] of integer;
> begin
>    // Incompatible types: got "{Array Of Const/Constant Open} Array of ShortInt" expected "Array[0..2] Of LongInt"
>    data := [1,2,3];
> end.

With recent FPCs you can however do this:

program test;
var
   data: array[0..2] of Integer;
   tmp: array of Integer = Nil;
begin
   tmp := [1,2,3];
   Move(tmp[0], data[0], SizeOf(data));
end.




More information about the fpc-pascal mailing list