Marco van de Voort wrote:
I'm not sure why you do it like this -- perhaps it's just a relic from ancient times when GPC didn't know about importing interfaces. In this case, I'd suggest to get rid of it. Otherwise, any ideas for fixing this are welcome.
The only other solution I can think of:
- such modules shouldn't be allow to initialise, and have stuff that must be
initialised global in the implementation part. (the part that is separately compiled)
How? When the module is compiled, the compiler doesn't know how it will be used?
(Note that I don't judge whether it should be unsupported or not. I just come up with some possible ideas)
[thinking] I see that I have made some assumptions, which I'll try to explain:
It depends on how your link between the header and the module sourcefile is.
When compiling the module sourcefile, is the header then checked? Iow are the header and implementation linked together (so that the header of module a is parsed before with the compilation of the module is started).
If that isn't done (the header is no true interface but a mere EXTERNAL declaration), then it is impossible, because the vars are declared twice, in header and module.
-------------
Otherwise a module could get a special pragma to declare it old style, and then the compiler should not generate initialisation code for interface variables. (mangled) Names of variables to be initialised globally could be stored in .gpi, and initialisation/finalisation code generated when the main module is compiled.
- All initialisation for the variabeles in the INTERFACE, are done by the
mainprogram.
Again how? All the compiler sees (in Ian's example) are `external' declarations, and initializing all external variables would in general be wrong.
Everything imported via #include should be initialised by the mainprogram, and it could be communicated back via de unit (non-object code) file. (gpi with GPC IIRC)
A main program then has to check all involved GPI files. Not only the modules that the mainprogram includes, but also deeper nested stuff.