David Wood 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. 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?
Detecting uninitialised variables is hard problem. For externals there is nothing gpc can do: gpc sees only one module at any given moment and initialisation can be in a different module. For local variables there is '-Wuninitialized' option, but it is not fool-proof. AFAIK it depends on optimiser and will miss variables which are not intersting for optimisation. It will also flag some variables which are initialised, but in non-obvious way (say inside conditional).
Currently uninitialised variables gets what happen to lie in memory -- on Unix kernel fills memory with zeros at program start, so global variables get binary zero value. That catches nil pointers. One can imagine more "nasty" values (Not a numbers for floating point, pseudo-random for integers) but nothing of such sort is implemented.
gpc will do some initialisatins automaticaly. If that does not work, it is a compiler bug. And it is easier to fix such bug then to introduce extra checks.