[fpc-pascal] Pass open array to static array?
pascaldragon at googlemail.com
Sun Mar 15 23:40:59 CET 2020
Ryan Joseph via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
So., 15. März 2020, 19:58:
> > 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, data, SizeOf(data));
> > end.
> yeah I figured you can do something similar with generics:
> generic procedure Move<T>(source: array of T; var dest);
> bytes: SizeInt;
> bytes := length(source) * sizeof(T);
> Move(source, dest, bytes);
> specialize Move<GLfloat>([0.0, 0.5, 0.0,
> -0.5, -0.5, 0.0,
> 0.5, -0.5, 0.0],
> 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
The message of the compiler is a bit misleading. It's a *dynamic* array
that is created there, not an *open* array. Open arrays only exist when
being passed directly to a parameter.
But to answer why the compiler does not do it: because I simply have not
had the time to implement it! The main point of dynamic array constructors
was to have them Delphi compatible. Support for static arrays is something
I have planned though (and you're not the first to ask for it).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal