comp.lang.c FAQ list
How can I make a sort of ``semi-global'' variable,
private to a few functions spread across a few source files?
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:
- Pick a unique prefix
for the names
of all functions and global variables
library or package of related routines,
and warn users of the package
not to define
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.'')
- Use a name beginning with an underscore,
since such names shouldn't be used by ordinary code.
(See question 1.29 for more information,
a description of the ``no man's land''
between the user and implementation namespaces.)
It may also be possible to use special linker
to adjust the visibility of names,
but any such
are outside of the scope of the C language.
about this FAQ list