[fpc-devel] ref count issue with out param

Den cyraid at gmail.com
Mon Jun 15 20:47:26 CEST 2015


> It is similar to type tarray = array [1..10] of longint; procedure 
> p(const a1 : tarray;var a2 : tarray); begin a2[1]:=4321; 
> writeln(a1[1]); // surprise end; var arr : tarray; begin arr[1]:=1234; 
> p(arr,arr); end. The only way to prevent this (of course, such a 
> simple case could be detected by the compiler but one can always 
> construct an example which works around this detection), is to turn 
> off the const optimization that const allows the compiler to pass only 
> a reference, but I am pretty sure, people will not be happy about this :)
Correct. Would definitely not be happy about this. :)

- Dennis




More information about the fpc-devel mailing list