How can I declare a constant array as the return type? Or constant pointer to constant data?
I tried:
Simba Code:
Function Foo: const array[0..2] of integer; //does not compile.
var
myarr: array[0..2] of Integer = [2, 5];
begin
result := myarr;
end;
begin
Foo[0] := 10; //should fail. Result is constant.
end.
Simba Code:
const
arr = ['1', '2'];
Function Foo: ^char;
begin
Result := @arr[0]; //can't.. expected variable..
end;
Function Foo2: const ^char; //can't..
begin
Result := @arr[0];
end;
I know you can do this:
Simba Code:
type
PInt = ^Integer;
const
Foo = PInt(100);
but why is there no way to have const return types?
Even this fails:
Simba Code:
type pInt = ^Integer;
Function Foo: PInt;
var
I: Integer;
const
Res: PInt := (@I);
begin
I := 10;
result := Res;
end;
const
I: PInt := Foo;
begin
I^ := 20; //biggest wtf..
writeln(I^); //prints 20 -__-
end.
Is there seriously no way to have data and pointed to data immutable? I want to have a const pointer. One that cannot be written to or even immutable pointers that cannot be changed once initialized..
Impossible?