lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Shmuel Zeigerman <shmuz@013net.net> wrote:
(01/07/2022 08:39)

>What I'd like to understand is why the real behavior is different and 
>how to prevent such troubles in the future.
>So the 2 questions remain:
>1. Whether the lack of the word 'static' is a bug here?
>2. Does some GCC switch exist to prevent such behavior?
>
>-- 
>Shmuel

I think it may not be a name collision, as you already suspect, so there may be differences in the GCC process caused by code used to make it work on a different platform. There might be a switch to fix it, but it may be better to direct the behaviour with the code, so if 'static' fixes it, it suggests a lack of defined value when declared. Use of static in C is like making a global whose address is known locally, and the difference in initialising is also that of a local, i.e. in C there is no initialising unless you ask for it, so the subsequent use of a static local gets whatever was put there before, or some otherwise undefined (likely random) stuff.

I don't know if variants of a compiler are always rigorous about what happens to a variable at declaration time, but if you really want a local to be initialised, an array is best declared like "int N[5]={}" (minus quotes) to initialise all five elements to 0. Use of static won't initialise a variable either, it just makes sure that what gets put there, stays there between function calls..