Vinzent Höfler schrieb: > Florian Klaempfl <[email protected]>: > >> Vinzent Höfler schrieb: >>> Florian Klaempfl <[email protected]>: >>> >>>> A VAROUT parameter could have the same semantics as VAR except that the >>>> compiler does not expect that it is needed that it is initialized. But >>>> be warned: with such a parameter type you can easily create memory >> leaks >>>> with automated types like ansistrings. >>> I don't understand the issue. >> Indeed, I noticed :) > > Care to explain why the programmer can easily determine something which seems > to be an unsolvable problem for the compiler, although both have exactly the > same information?
Because a VAROUT parameter would be simply overwritten by the callee even if it contains a valid automated type: procedure p(varout v : ansistring); begin v:='asdf'; end; var s : string; begin s:='asdf'; s:=s+s; p(s); <-- memory leak, s+s is never freed end; OUT does prevent this because s is cleaned up before p is entered. OTOH, OUT causes a crash if s is filled with garbage. _______________________________________________ fpc-devel maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-devel
