On 07 Mar 2010, at 00:13, Juha Manninen wrote:

> I remember having garbage in strings in Delphi when I assumed they are empty.
> Or was it only with function's string return value, I am not sure.
> Anyway, after that I was careful to always assign my strings.

You're right that it can be different in case of function results. In case the 
function result is passed to the function via a hidden call-by-reference 
parameter, then if you write "x:=func(...)", the "result" variable inside func 
may directly refer to "x" rather than to some temporary value. And I think that 
when inlining, the compiler may also reuse previously used ansistring temps for 
local variables of inlined functions (which still may contain a value from 
evaluating a previous expression).

So even with reference-counted types, it's indeed best to always explicitly 
assign a value if you want to be certain that they contain said value.


Jonas_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to