is "extern" ambiguous
DBrown at Hi-Multics.ARPA
DBrown at Hi-Multics.ARPA
Fri Mar 30 06:13:00 AEST 1984
From: Dave Brown <DBrown at Hi-Multics.ARPA>
There is a difficulty (I won't call it a bug) with the
understanding that PCC and Lint have of what "extern" and
"static" mean.
We have several programs obtained from a Vax site which contain
code like:
<beginning of file>
main () {
extern int proc1();
...
proc1();
...
}
static proc1() {
...
}
<end of file>
PCC and Lint notice the "extern" declaration and remember that
the author has warned them that they may have to issue an
external reference. They then find the procedure in the file,
decide that they can link it without issuing an external ref for
LD, and quite properly do so.
Unfortunatly, at this point they seem to have lost track of the
fact that the first declaration asserted something that wasn't
true: it claimed that proc1 was a "normal" external function.
We now see that proc1 isn't a normal external, but instead is a
"static" (meaning private) function.
To quote the white book, ".. static variables and functions
provide a way to conceal data objects and any internal routines
that manipulate them so that other routines and data cannot
conflict even inadvertantly."
For obvious reasons we prefer to have the function declared the
same way (as static) every time, and have redeclared it that way
so Lint won't complain so loudly.
This raises two questions:
(1) Does anyone have a compiler which DEMANDS statics be
predeclared as externs? (ie, can we fix the code without making
that a machine- or compiler-specific fix), and
(2) Are the Unix(tm) compilers and Lint correct in accepting
this construct or should they be regarding this as a legal but
non-portable construct?
--dave (unix hack on a bun) brown
There is a difficulty (I won't call it a bug) with the
understanding that PCC and Lint have of what "extern" and
"static" mean.
We have several programs obtained from a Vax site which contain
code like:
<beginning of file>
main () {
extern int proc1();
...
proc1();
...
}
static proc1() {
...
}
<end of file>
PCC and Lint notice the "extern" declaration and remember that
the author has warned them that they may have to issue an
external reference. They then find the procedure in the file,
decide that they can link it without issuing an external ref for
LD, and quite properly do so.
Unfortunatly, at this point they seem to have lost track of the
fact that the first declaration asserted something that wasn't
true: it claimed that proc1 was a "normal" external function.
We now see that proc1 isn't a normal external, but instead is a
"static" (meaning private) function.
To quote the white book, ".. static variables and functions
provide a way to conceal data objects and any internal routines
that manipulate them so that other routines and data cannot
conflict even inadvertantly."
For obvious reasons we prefer to have the function declared the
same way (as static) every time, and have redeclared it that way
so Lint won't complain so loudly.
This raises two questions:
(1) Does anyone have a compiler which DEMANDS statics be
predeclared as externs? (ie, can we fix the code without making
that a machine- or compiler-specific fix), and
(2) Are the Unix(tm) compilers and Lint correct in accepting
this construct or should they be regarding this as a legal but
non-portable construct?
--dave (unix hack on a bun) brown
More information about the Comp.unix.wizards
mailing list