[fpc-devel] Feature request/discussion - SetLengthNoInit

Ryan Joseph genericptr at gmail.com
Thu Sep 17 05:03:19 CEST 2020

> On Sep 17, 2020, at 9:59 AM, J. Gareth Moreton via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> type generic TMyArray<T> = record
>   Data: ^T;
>   Length: PtrUInt;
> end;
> The compiler will complain about T being an unresolved forward declaration.  Outside of specifying a second parameter for the pointer type (which would be a little unfriendly for third-party users), there isn't really a way around this.

To be clear all the features work but it's not as optimized as dynamic arrays and could be cumbersome with arrays of records.

I think you're supposed to redeclare a pointer to T:

type generic TMyArray<T> = record
    TP = ^T;
    Data: TP;
    Length: PtrUInt;

	Ryan Joseph

More information about the fpc-devel mailing list