[fpc-pascal] Warning "Local variable seems to be not initialized" on dyn array

Florian Klämpfl florian at freepascal.org
Tue Mar 10 18:52:52 CET 2015


Am 10.03.2015 um 18:43 schrieb Jürgen Hestermann:
> 
> Am 2015-03-10 um 18:16 schrieb Lukasz Sokol:
>> On 10/03/15 16:08, Jürgen Hestermann wrote:
>>> Then please tell me, what do you (or anybody else) gain from this warning?
>>> Especially, as it claims something that is definitely not true (for managed types).
>>> It may even misguide some to add initialisation code without need and
>>> it distracts from the realy important messages.
>>>
>> Just googled this out:
>> (edit: meant this actually)
>> http://lazarusroad.blogspot.com.br/2012/07/does-it-matter-how-dynamic-arrays-are.html
>>
>> and this immediately after:
>>
>> http://lazarusroad.blogspot.co.uk/2012/07/cost-to-supress-warning-and-how-not-pay.html
>>
>>
> 
> I am not sure what these links should tell me.
> I could not find any hint that omitting the warnings for managed types would do any harm.
> Just the opposite. As I already suspected, people are adding code just to get rid of the warning
> (or they have the time and leisure to disable these warnings for each project over and over again):
> Cite from the second link:
> 
> "Although the performance impact is mostly negligible, is extra code anyway.
> In my case i initialize the parameter explicitly so *out* would add redundant code.
> There's an alternative to suppress the message: add the directive {%H-} in front of the variable
> that is being passed to the procedure."
> 
> Again I can't find any legimitation for having these warnings.

Using dyn. arrays without initialization makes litte sense in real world programs, so those warnings
have their use.

Further, automatic initialization of managed types is not something to help lazy programmer but
simply needed for the compiler so it is able to handle memory management.

Last but not least, if a type is initialized manually and automatically, the compiler is supposed to
remove the unnecessary ininitalization (currently it cannot do this always on all platforms though)
to avoid any speed penalty.



More information about the fpc-pascal mailing list