Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!rpi!uupsi!sunic!ericom!eos.ericsson.se!epames From: epames@eos.ericsson.se (Michael Salmon) Newsgroups: comp.lang.c Subject: Re: Scope of 'static' variables Keywords: extern, static Message-ID: <1990Dec7.131700.11533@ericsson.se> Date: 7 Dec 90 13:17:00 GMT References: <7744.27500de8@jetson.uh.edu> <2175@tuvie> <1990Dec7.051955.2883@mintaka.lcs.mit.edu> Sender: news@ericsson.se Reply-To: epames@eos.ericsson.se Organization: Ericsson Telecom AB Lines: 22 In article <1990Dec7.051955.2883@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