Scope of 'static' variables
Kaleb Keithley
kaleb at thyme.jpl.nasa.gov
Sat Dec 8 08:48:59 AEST 1990
In article <14680 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <1990Dec7.051955.2883 at mintaka.lcs.mit.edu> dstailey at 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 at thyme.jpl.nasa.gov
You can please all of the people some of the time,
More information about the Comp.lang.c
mailing list