[fpc-pascal] SetLength warnings - request

Derek Edson mr.ed.123 at gmail.com
Sat Dec 29 22:00:04 CET 2018


Surely the point of a hint/warning is to point out a potential issue that
the programmer may wish to correct.

It should therefore be possible to change your code such a way that the
hint/warning can be resolved so that it is no longer printed. This should
not entail redundant or unnecessary code.

The Wiki still indicates that SetLength only allocates the space, but it
does not initialized the memory. Although this is probably incorrect for
"array of string" to prevent memory leaks.

I agree that SetLength should be a var parameter, as it can be used to
reassign the size of a dynamic array, not just creating them. This must
mean that the value passed is used, even for an assumably uninitialized
array, so it must be initialized.

Readability of the code is not enhanced by doing an unnecessary static
initialization, you could do an equally ugly "pointer(var) := nil"

Would it not be simpler to have the compiler initialize all dynamic array
variables to nil, like for string variables, which should prevent the
uninitialized warning/hint without requiring special treatment for handling
the SetLength function.

It does require that the compiler recognizes its own initialization of
dynamic array variables.


Derek

On Sun, 30 Dec 2018 4:35 am Yuriy Sydorov <jura at cp-lab.com wrote:

> On 29.12.2018 16:19, Benito van der Zander wrote:
> > Hi,
> >
> >> even if there's closed issue
> https://bugs.freepascal.org/view.php?id=34169 I would like to ask if it
> can be reconsidered.
> >>
> >> The subject is that SetLength now gives warning: Variable "dynamic
> array" of a managed type does not seem to be
> >> initialized
> >>
> >> in 3.3.1 and 3.1.1 while it doesn't give any warning in stable 3.0.4
> >>
> >
> > seriously that is such a bullshit warning.
> >
> > SetLength is called to initialize the variable, of course the variable
> is not initialized before. If it was initialized,
> > we might not even need to call SetLength
>
> The current FPC trunk issues only a hint for the SetLength().
>
> Yuriy.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20181230/4fcf0dff/attachment.html>


More information about the fpc-pascal mailing list