Also read this:
https://stackoverflow.com/questions/30410064/pascal-pointer-to-an-array-of-unknown-size
If I change lines 8 and 11 to the code below I got the same address.
sz2 := SizeOf(TInt16_array(@data));
adr2 := Integer(Pointer(@TInt16_array(@data)[1]));
because here you convert not the array but the pointer to the array!
but dynarray is not merely pointer to values, the dynarray has a whole frame of ARC data BEFORE the values, and compiler would automatically change the data in that "before values" frame with you deal it with dynarrays.
so frankly, FPC should had baffled here and denied such a type miscast, if he denied my original one
but okay, for the sake as uniformity and completeness;
type
Tint16_original = array[0..10] of int16;
.....
adr1 := Integer(Pointer(@TInt16_original(@data)[1]));
adr2 := Integer(Pointer(@TInt16_array(@data)[1]));
Will it compile? No?
Well, if it will - you would see addresses do not match.
If it won't - you see those types are FUNDAMENTALLY DIFFERENT.
One only compiling with "@data" - pointer, not values. Another only compiling with "data" - value not pointer.
Frankly, i do not see what you say you see.
To me typecasts with @data do not compile, never and no way.
program Project1;
type
ti = smallint;
pi = ^ti;
tsa = array [0..4] of ti;
tpa = packed array [0..4] of ti;
tda = array of ti;
psa = ^tsa;
ppa = ^tpa;
pda = ^tda;
var
p0: Pointer;
p1: pi;
data: array [0..4] of ti;
begin
// {$T-} or {$T+}
p1 := @data[1];
p0 := @data;
// all those three are compiled fine
p0 := @tsa(data);
p0 := @tpa(data);
p0 := @tda(data);
// those three are not compiled, but errors differ
p0 := @tsa(@data);
p0 := @tpa(@data);
p0 := @tda(@data);
{ if T- mode was set, then the errors would be:
project1.lpr(33,10) Error: Illegal type conversion: "Pointer" to "tsa"
project1.lpr(34,10) Error: Illegal type conversion: "Pointer" to "tpa"
project1.lpr(35,14) Error: Can't assign values to an address
if T+ mode was set, then the errors would be:
project1.lpr(33,10) Error: Illegal type conversion: "^Array[0..4] Of SmallInt" to "tsa"
project1.lpr(34,10) Error: Illegal type conversion: "^Array[0..4] Of SmallInt" to "tpa"
project1.lpr(35,14) Error: Can't assign values to an address
}
ReadLN;
end.
Also note that merely typecasting somethign to dynarray type already tries to WRITE somewhere into the @data
Did you expect it?