Wood David wrote:
Thanks Waldek,
That's a really big help. Having migrated from DEC Pascal which had very different MODULE integration syntax I had never picked up on the importance of the IMPORT clause, especially as the code has always compiled without a hitch.
So to say by accident (just throwing things together at link time). Missing initializers are just one symptom of the problems. (In fact, GPC did use a different mechanism for calling initializers until some time ago. This would work independently of imports, but rely on some more or less obscure linker internals which would work on some systems and not on others (which meant that GPC on those latter systems was more or less unusable). So I think it's better to have one way (and in particular, one EP/BP (import/uses) compatible way) working on all systems than an undocumented way (bypassing imports) working only on some.
I wonder if there is any way gpc can pick up on the use of declarations which haven't been properly initialised, either at compile time or run-time?
As Waldek said, at compile time it's nearly impossible for global (especially cross-module) stuff. At runtime it's possible, but with huge effort AFAICT. (One might have to stick a flag to each variable or record/array field to be sure, which by the way would break binary compatibility to C and other languages etc. Not something I plan to do in the nearer future ...)
David Wood wrote:
Frank,
I don't know if there is a bug number for this but I am
attaching two really
small bits of code which show it up. It's the only
'genuine' bug I have
ever really come across in gpc. Basically, the globally
defined string
doesn't seem to get any length so whenever something is
assigned to it, the
contents vanish.
Your program is buggy: you forgot to 'import' your module. Even if you want to access objects in the module via external name you still need to 'import' it so its inititializer is run automatically. If you want main program to be in other language, then you need to call 'init_With_string' explicitly.
GPC now also allows `--init-modules=With_String' on the command-line (when compiling the main program). If the main program is not in Pascal, you have to do more calling, see demos/gpc_c_*
Frank