static functions

g-frank at gumby.UUCP g-frank at gumby.UUCP
Wed Feb 20 08:13:26 AEST 1985


> What does it mean when you declare a function as:
> 
> static char *
> func ()
> ....
>

  It means that the name of the function is not visible outside the source
file in which it was defined.  This is very useful for restricting the scope
of function names, which are by default visible everywhere, just like
variables declared outside any function.  So, if you want every compiland
to have its own function called "error_handler," for example, just declare
error_handler static every time you define it (in different files, obviously),
and you won't have to worry about name scope (unless you want to).

  By the way, this same trick goes for variables declared outside of functions.
They are obviously static, but by default their names are known globally.  If
you want statics global within an entire source file, but not visible outside,
just declare them "static" explicitly, and their scope will be restricted to
the file in which they are declared.


-- 
      Dan Frank

	  Q: What's the difference between an Apple MacIntosh
	     and an Etch-A-Sketch?

	  A: You don't have to shake the Mac to clear the screen.



More information about the Comp.lang.c mailing list