Scope of 'static' variables
Doug Stailey
dstailey at gnu.ai.mit.edu
Fri Dec 7 16:19:55 AEST 1990
In article <2175 at tuvie> hp at vmars.tuwien.ac.at (Peter Holzer) writes:
>elee6i5 at jetson.uh.edu writes:
>
>
>The static variables usually get names which cannot clash with
>other variables (something like L0001 (or just
>BeginDataSegmentOfThisModule + Offset), C external variables are
>prefixed with an underscore), and are not exported to other
>modules. So static variables are just like globals but no other
>function knows its name, so it cannot be referenced (except
>through a pointer).
>
>Turbo C does it this way, and all other compilers I know do it
>similarly.
>--
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?
--
disclaimer: This message is sold by weight, not volume. Contents may have
settled during shipment.
More information about the Comp.lang.c
mailing list