Odd question re: extern vs. static
Jonathan A. Chandross
jac at paul.rutgers.edu
Sat Jul 22 07:30:08 AEST 1989
scs at adam.pika.mit.edu (Steve Summit)
> The following fragment looks illegal, and probably is:
> extern int f();
> static int f;
Nope. It has worked in pcc based compilers for years. gcc breaks on
this, however.
> Marking a file-scope symbol "static" is supposed to make it
> private; to protect it from interfering with global variables in
> other source files. The problem here is essentially that a
> symbol from another source file is interfering with the local,
> static symbol.
I take a different, more modular, approach to declaring external
functions in a header file:
#define EXPORT
#define LOCAL static
EXPORT int foo()
{
extern float bar();
....
}
LOCAL float bar()
{
....
}
The point is that I don't want to worry in foo() where bar() is
defined; that is, in this module or in some other module. And yet
I want the modularity of declaring bar in each function where it
is used, not once per file. Incidentally, the same thing goes for
global variables.
Jonathan A. Chandross
Internet: jac at paul.rutgers.edu
UUCP: rutgers!paul.rutgers.edu!jac
More information about the Comp.lang.c
mailing list