Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!jac From: jac@paul.rutgers.edu (Jonathan A. Chandross) Newsgroups: comp.lang.c Subject: Re: Odd question re: extern vs. static Keywords: extern, static, name clash Message-ID: Date: 21 Jul 89 21:30:08 GMT References: <12878@bloom-beacon.MIT.EDU> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 41 scs@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@paul.rutgers.edu UUCP: rutgers!paul.rutgers.edu!jac