Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!usc!elroy.jpl.nasa.gov!thyme!kaleb From: kaleb@thyme.jpl.nasa.gov (Kaleb Keithley ) Newsgroups: comp.lang.c Subject: Re: Scope of 'static' variables Keywords: extern, static Message-ID: <1990Dec7.214859.13727@thyme.jpl.nasa.gov> Date: 7 Dec 90 21:48:59 GMT References: <2175@tuvie> <1990Dec7.051955.2883@mintaka.lcs.mit.edu> <14680@smoke.brl.mil> Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 28 In article <14680@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <1990Dec7.051955.2883@mintaka.lcs.mit.edu> dstailey@gnu.ai.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) > >"static" applies to the function; it has NOTHING to do with the value >returned. Thus "function returning a static" is incorrect terminology. >"The function is statically defined" would be acceptable. > > extern char *example(void); > > char *example(void) { > static char buffer[100]; > /*...*/ > return buffer; > } To (perhaps) clarify. A static function is not "public", i.e. you may not call a static function from another module; it is invisible to all but file it is in. By default, all C functions are "public" unless explicity declared "private" with the static keyword. -- Kaleb Keithley Jet Propulsion Labs kaleb@thyme.jpl.nasa.gov You can please all of the people some of the time,