Thank you.
You are welcome.
So, since constant statically sized array modifications are caught by the compiler:
program staticarr;
{$mode objfpc}
{$WriteableConst off}
type
ArrInt3 = array[0..2] of integer;
procedure procarr3(const arr: ArrInt3);
begin
arr[0] := 4;
end;
var
arr3: ArrInt3 = (1,2,3);
begin
procarr3(arr3);
end.
Free Pascal Compiler version 3.2.2 [2022/08/31] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling staticarr.pas
staticarr.pas(10,4) Error: Can't assign values to const variable
staticarr.pas(19) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
program staticarr2;
{$mode objfpc}
{$WriteableConst off}
type
ArrInt3 = array[0..2] of integer;
procedure procarr3(var arr: ArrInt3);
begin
arr[0] := 4;
end;
const
arr3: ArrInt3 = (1,2,3);
begin
procarr3(arr3);
end.
$ fpc staticarr2.pas
Free Pascal Compiler version 3.2.2 [2022/08/31] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling staticarr2.pas
staticarr2.pas(17,16) Error: Can't assign values to const variable
staticarr2.pas(19) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
And, as I demonstrated earlier:
This does compile and run:
program dynarr2;
{$mode objfpc}
{$WriteableConst off}
type
ArrInt = array of LongInt;
procedure procarr(const arr: ArrInt);
begin
arr[0] := 4;
end;
begin
procarr([1,2,3])
end.
But this fails:
program dynarr2;
{$mode objfpc}
{$WriteableConst off}
type
ArrInt = array of LongInt;
procedure procarr(const arr: ArrInt);
begin
arr[0] := 4;
end;
begin
procarr([1,2,3])
end.
Free Pascal Compiler version 3.2.2 [2022/08/31] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling dynarr2.pas
Linking dynarr2
15 lines compiled, 0.1 sec
Should the above case (that does compile and run) be reported as well? I would indicate it is related to the
FPC issue 39986(as it is a
const paramater which might be handled differently?)