prev up next   top/contents search

comp.lang.c FAQ list · Question 1.9

Q: How can I make a sort of ``semi-global'' variable, that is, one that's private to a few functions spread across a few source files?

A: You can't do this in C. If it's impossible or inconvenient to put all the functions in the same source file, there are two usual solutions:

  1. Pick a unique prefix for the names of all functions and global variables in a library or package of related routines, and warn users of the package not to define or use any symbols with names matching that prefix other than those documented as being for public consumption. (In other words, an undocumented but otherwise global symbol with a name matching that prefix is, by convention, ``private.'')
  2. Use a name beginning with an underscore, since such names shouldn't be used by ordinary code. (See question 1.29 for more information, and for a description of the ``no man's land'' between the user and implementation namespaces.)

It may also be possible to use special linker invocations to adjust the visibility of names, but any such techniques are outside of the scope of the C language.

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North