Scope of 'static' variables

Michael Salmon epames at eos.ericsson.se
Sat Dec 8 00:17:00 AEST 1990


In article <1990Dec7.051955.2883 at mintaka.lcs.mit.edu> Doug Stailey writes:
>But what if you want to call a function returning a static from another
>source module?  Say for instance, in main.c you have a function declared:
>static char *get_cmd(FILE *fp)
>and you want to call it from misc.c.  You can't say
>extern static char *get_cmd(FILE *fp)
>since most compilers will respond with the "too many storage classes" error.
>If I declare it: extern char *get_cmd(FILE *fp) this gives a warning
>under GCC.  I'm not sure whether it works with Turbo C.  How should
>such a function be declared externally?

Static has no meaning when used to describe a return value, instead
what you are doing is declaring that the function is local to the file
in which it is declared. If you just delete the static from the
declaration then you can do what you want. Some authors of C books
advocate #defining private to be static and that makes the declaration
more obvious although I personally believe that making C look like
something else is not particularly desireable.

Michael Salmon
L.M.Ericsson
Stockholm



More information about the Comp.lang.c mailing list