-----Message d'origine----- De : gpc-owner@gnu.de [mailto:gpc-owner@gnu.de] De la part de Frank Heckenbach Envoyé : March 15, 2006 11:29 À : gpc@gnu.de Objet : Re: export vs static
Pascal Viandier wrote:
I would like to submit a case on which I spent some time. It occurred with sources converted to GPC from SUN Pascal with an automated script.
In the interface section of a module, the following statements:
Export MyModule = (A); .... Var A : Integer = 4; attribute(static); ....
This module compiles with no complaint. However for all modules importing MyModule -AND- using A, gpc issues the <error undefined reference to 'A'>.
The problem is: SUN Pascal understands the "static" directive as in C, so
the
statements above are correct and work - as in C -, but not for GPC.
How so? In C, static means file-scope, i.e. static declarations are not visible from other files:
/* a.c */
static int a;
/* b.c */
extern int a;
int main () { a = 42; }
# gcc a.c b.c /tmp/ccKBFfHh.o: In function `main': b.c:(.text+0x1e): undefined reference to `a'
Doesn't work in C.
Sorry, my explanation was missing details. The interface section was previously in a header file - like in C - included with #include in other modules. All these modules get their own copy of the variable with the same initial value. This was mainly used for default values and it was the way to do it because SUN Pascal did not allow initial value to variables in the declaration part (at least the version used at this time). Also with SUN Pascal all symbols are exported by default (again like in C). In this case, this works as expected - in C too -.
I know the difference between the two "static" flavours but it would have
been
of great help if gpc had issued at least a warning when compiling MyModule. Something like: "Cannot export a static variable" had saved me some
difficult
hours.
Yes, this might be useful.
Thanks. When you have hundreds of header and sources files in various programming languages spread in many directories, the sooner a compilation problem is detected the better IMHO.
I did not found any reference to the directive "static" in the 7185 or 10206
Yes, it's a nonstandard extension.
A useful one indeed. But a bit misleading with its C homonym ;-)
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8
Kind regards
Pascal Viandier