Nick Ioffe wrote:
Here're 2 more strange behaviours with interface vs. implementation global variables definitions. May be they will help you to find out what is wrong in modules initialization.
Thanks, but actually I know what is wrong. It will just take some effort to fix it. ;-)
Problem I:
I slightly change the previous expample - declare my_str_var in both mod1 module interface and implementation, in mod2 implementation and in my_main global var definitions block.
What happens is that although each variable should be local for the module (at least that is what the common sense tells me) all the variables behave like there're the same variable. I've checked it with debugger and it points to the same address in all modules.
Problem II. As we've seen in problem I repeating the declaration in module implementation solves the problem of accessing the strings. Now I need to declare the array of string:
[...]
When I compile it I get the following errors: mod3.pas:15: redeclaration of 'My_buff' mod3.pas:10: previous declaration of 'Mybuff'
then I change the source as follows:
[...]
Now everything compiles good.
Why? What is the difference?
I think both problems are because GPC ignores duplicate declarations of the same type (equivalent array declarations are not the same type in Pascal, but a common `type' definition is).
In part that's a relic from the C compiler. However, when I tried to fix it, I was told that some people apparently use GPC in such strange ways (i.e., using include files like in C instead of modules or units, so the same variable is declared externally and normally in the same file). I guess sometime we have to break this, anyway, and they'll have to rewrite their code ...
(These problems are unrelated to the problem of missing initializations.)
Frank