On Mon, 14 Aug 2023, Martin Frb via fpc-devel wrote:

In the below code, the array is resized (and more important relocated in mem) inside the function "bar".

The commented line (without "with") works as expected.

The "with" line has a different behaviour. I guess it is by design. Just wanted to confirm.

The version with "with" prints 12345 for  "  writeln(a[i,j].x);"
For all I can tell the return value of "bar" was written to the old address of that array-entry.

Does "with" take the "address" of the value, and operate on that address, even if the address of that value could change within the "with" statement.

You may not do this. It is even documented.

See the remark at the end of this page:

https://www.freepascal.org/docs-html/current/ref/refsu62.html#x172-19600013.2.8

Michael.
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to