On 26/06/16 11:09, Jürgen Hestermann wrote:
Am 2016-06-26 um 01:19 schrieb Karoly Balogh (Charlie/SGR):
No. Local variables are not initialized by default. Managed type or not,
doesn't make a difference.
This is not true.
Local variables of managed types are of course initialized!
If you declare
var S : String;
then it is of course initialized to nil.
Otherwise the (random) pointer stored in S would be used
to change the reference counter when you assign:
S := '';
My understanding (having been bitten by this) is that the requirement is
only that S has a "sensible" value, so that the heap is not corrupted on
the assignment, as you indicate. The compiler can re-use another
variable instead, so the unset value is some other valid string.
Colin
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal