[fpc-devel] Managed Types, Undefined Bhaviour
Michael Van Canneyt
michael at freepascal.org
Sat Jun 30 14:50:52 CEST 2018
On Sat, 30 Jun 2018, Willibald Krenn wrote:
>>> Managed fields of records are "setup" ;)
>>
>> I will add a section about this in the documentation, seeing that people
>> often confuse the 2 concepts.
>
>
> In an ideal world, either the language would not let you write code that has random behavior or the compiler would enforce this.
There is no random behaviour.
>
> procedure global(memo1: TMemo);
> begin
> A:=X(3);
> A[0] := 5;
> A[1] := 4;
> B:=X(3);
> // the following will print 5 twice
> memo1.lines.add('GlobalA0: %d',[A[0]]);
> memo1.lines.add('GlobalB0: %d',[B[0]]);
B[0] is not initialized. Printing the contents can print anything.
A and B are different arrays, with length 3, The compiler ensures this.
But their content is not initialized. Printing the content may therefor
result in any possible vallue.
Your code in essence does the same as
Procedure something;
var
B : Array[0..2] of integer;
begin
Writeln(b[0]);
end;
And - Lo - it behaves the same...
Michael.
More information about the fpc-devel
mailing list