[fpc-devel] Wrong docs: not initialized global variables
lazarus at kluug.net
Sun Mar 25 00:09:46 CET 2018
On 24.03.2018 23:33, Ondrej Pokorny wrote:
>> Another question about this sentence in FPC docs: "Managed types are
>> always initialized: in general this means setting the reference
>> count to
>> zero, or setting the pointer value of the type to Nil."
>> Does it mean I can assume a local string variable is always
>> the routine is called) initialized to ''? I.e. that TestB always
>> For managed types this is indeed guaranteed. Otherwise there'd be
>> exceptions upon the first use of the variable as the RTL would assume
>> that the value is valid.
> OK, thanks. My assumption was that setting local managed types to nil
> is guaranteed only once at the first routine call. And that it is an
> implementation detail if it is niled at the second call or reused from
> the first call.
> I probably mixed it up with the Result variable (what Maciej wrote about).
I found the source of my assumption, I get a compiler warning in this case:
function Test: string;
var S: string;
S := S + 'a';
Result := S;
StringsTest.lpr(5,8) Warning: Local variable "S" of a managed type does
not seem to be initialized
Why do I get the compiler warning when the variable is indeed guaranteed
to be initialized to nil/empty string?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel