Peter Gerwinski wrote:
Yes, I think that's this problem. If you compile a unit with `-S', you'll find that global variables in the implementation
... where it _must_ be like this ...
(* Why? *)
(as well as global variables in a program)
... where we should discuss about ...
are `local' instead of `global' or `comm'.
Global variables of the program must be in the data (and not in the stack) segment in order to circumvent limitations of the stack size. Normally, there is no need to make them visible to the linker because programs cannot be "used" (imported) by other Pascal programs, modules, or units. (In C, such variables are declared `static'.)
If you want to make a global variable of the program visible to the linker (and thus to external assembler routines), you can use the following trick:
Program Test; Var Foo: external Integer; Foo: Integer; begin end.
This produces a `comm' variable without `local'.
The first declaration of `Foo' tells the compiler that there is some external integer variable `Foo'. The second one allocates storage for this variable, remembering that it must be accessible from the external world.
Okay like this?
I think so, for the following reason: when GPC will get qualified identifiers and/or function overloading, the translation Pascal identifier -> asmname can't be as simple as it is now. Therefore, it's not wrong to get used to do special declarations for variables one wants to use externally.
What I find strange is the `external' in the example and having to repeat the declaration -- though I understand why it is currently necessary. I think in the long run, we should think of a better syntax for that.
Frank