[fpc-pascal] Feature announcement: Dynamic array extensions

Michael Van Canneyt michael at freepascal.org
Sun May 20 18:16:40 CEST 2018



On Sun, 20 May 2018, Mattias Gaertner wrote:

> On Sun, 20 May 2018 14:23:25 +0200
> Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>
>> Hello together!
>> 
>> I'm pleased to announce that after nearly a year various extensions for 
>> dynamic arrays have been finished. This includes the following features:
>> 
>> - support for array constructors using "[...]" syntax
>> - support for Insert(), Delete() and Concat()
>> - support for "+" operator
>> - support for dynamic array constants (and variable initializations)
>
> :)
>
> I hope 3.2 is coming soon.
>
>
>> [...]
>> === code end ===
>> 
>> For constants the dynamic array constants adhere to the writable 
>> constants switch $J. E.g. the following will result in an exception:
>> 
>> === code begin ===
>> 
>> {$J-}
>> const
>>    Test1: array of LongInt  = (1, 2, 3);
>> begin
>>    Test1[1] := 42;
>> end.
>
> This seems to be inconsistent with
>
> procedure Test(const a: TStringDynArray);
> begin
>  a[1]:='42';
> end;
>
> Isn't it?

The const in the parameters indicates that the pointer a cannot be assigned,
but the contents can be assigned when inside the procedure.
(we can discuss whether this behaviour is logical, but I suppose we
inherited this from Delphi)

Whereas a constant is something that is eternally constant throughout the
application. Normally, a constant is something that is replaced by its
value when the compiler encounters it the sources.

So in a sense, it does not exist at runtime, hence you cannot assign to it
either.

Michael.


More information about the fpc-pascal mailing list