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

Ryan Joseph genericptr at gmail.com
Sun Mar 15 15:04:13 CET 2020



> On Mar 15, 2020, at 8:53 PM, Howard Page-Clark via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> 
> 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.

yeah I figured you can do something similar with generics:

generic procedure Move<T>(source: array of T; var dest);
var
  bytes: SizeInt;
begin
  bytes := length(source) * sizeof(T);
  Move(source, dest, bytes);
end;

begin
  specialize Move<GLfloat>([0.0, 0.5, 0.0, 
    -0.5, -0.5, 0.0, 
    0.5, -0.5, 0.0], 
    data.verts);
end.

but why doesn't open arrays already do this? an open array is just a constant array so the compiler should know the arrays are compatible for assignments.


Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list