[fpc-devel] fpc-devel Digest, Vol 178, Issue 38
Nikolai Zhubr
n-a-zhubr at yandex.ru
Thu Feb 21 17:05:31 CET 2019
Hi,
21.02.2019 17:41, Martin Frb:
> On 20/02/2019 19:31, Franz Müller wrote:
>> It's a nice example why scoped variables would be in fact better,
>> because the value of i is undefined if the for loop is exited
>> normally. So even the original code wouln't work as expected, you
>> cannot rely on i>High(arr) in that case, it depends on the way the for
>> loop is implemented.
>> Using only the variable local to the loop would cause a compiler error, while using only the variable defined in the function body would not even cause a warning but leed to unwanted results.
>
> That does not need inlined variables.
>
> The compiler already has a warning about uninitialized vars. If not
> detected after a for loop, this should be improved (rather than adding
> some other workaround).
>
> And there is a command line switch to tread warnings as errors. So that
> problem is perfectly solve-able.
Actually no. Inline declarations (where implemented) are not limited to
a loop index and not even limited to a loop. If you have an option to
declare some few variables locally to some code block (e.g. FOR, as well
as IF, CASE, WHILE, etc), in case you know for sure from their meaning
that their values just make no sense outside of this very block, you
would know they do not leak out accidentally. This is certainly not the
same as detecting uninitialized variables. A variable might be
technically initialized, but at the same time its value might make no
sense outside of some scope (for the reasons of your business logic or
whatever else considerations).
Thank you,
Regards,
Nikolai
>
>
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
More information about the fpc-devel
mailing list