<p style="padding:0 0 0 0; margin:0 0 0 0;">Thanks for comprehensive answer. <span style="font-size: 10pt;">My other code really worked coincidentally.</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"><span style="font-size: 10pt;">This code:</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> SetLength(aArray, 400);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> <span style="font-size: 10pt;">writeln(PInt64(@aArray[0]-8)^);</span></p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">writes out 399.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">I'll use more conservative code.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">V.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">______________________________________________________________<br />
> Od: "Joost van der Sluis via fpc-pascal" <fpc-pascal@lists.freepascal.org><br />
> Komu: fpc-pascal@lists.freepascal.org<br />
> Datum: 12.01.2023 00:22<br />
> Předmět: Re: [fpc-pascal] Dynamic array question<br />
></p>
Vojtěch Čihák via fpc-pascal schreef op wo 11-01-2023 om 23:38 [+0100]:<br />
> is there a way how to have dynamic array "inside" another dynamic<br />
> array?<br />
<br />
Not in the way you want.<br />
<br />
You could define an 'array of array', though. Or an array of records<br />
that contain an array.<br />
<br />
The problem is that you make all kind of assumptions about the memory-<br />
layout of these arrays, which may not always be valid. Code that works<br />
this way might work coincidentally, but may break when switching to<br />
another compiler version or by enabling an optimization. <br />
<br />
So.. you must really, really have a good reason why you should try<br />
this. And if you do so, don't use dynamic types for tricks like this.<br />
They are not meant to be used as a a way to map directly into a memory<br />
location.<br />
<br />
And, in your case, one of the assumptions is wrong. At the start of a<br />
dynamic array it's length is stored. That will destroy your memory-<br />
layout.<br />
<br />
And te compiler will try to allocate/deallocate memory for the second<br />
array. One big mess.<br />
<br />
You could use a static array for the 'inside' array.<br />
<br />
Regards,<br />
<br />
Joost.<br />
_______________________________________________<br />
fpc-pascal maillist - fpc-pascal@lists.freepascal.org<br />
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br />