[Gambas-user] Variable reinitialized at each iteration of a loop structure

Jussi Lahtinen jussi.lahtinen at gmail.com
Tue Mar 28 19:48:47 CEST 2023


> not actually expected as p goes out of scope ...
>

Not true. p is never used outside of the scope. That would not compile.



> ... yet has the last value when it reenters this block,
>

This is because "int p;" gives the same memory address every time (not
guaranteed) without initializing it. So it will contain the value it used
to contain.



> Tit seems that on mint anyway, allocated memory is always zero, in this
> case it looks like the register is not reused.
>

No, this is also not guaranteed. Try to declare a big array and check if it
has only zeroes. One variable may hit some initialized space, but you
cannot rely on it.
C does only the minimal, that is also why it is so fast.


Jussi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230328/697ba3c2/attachment.htm>


More information about the User mailing list