Variables

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Wed Nov 14 15:55:57 AEST 1984


>  I am trying to write a set of functions and procedures in C which will be used 
> as a set of library routines. But I can not find any way to make the variables
> used inside these routines unavailable to the applications program.

This is what file "static" is for.  C provides only two levels of externs:
globally known ("extern", default) and private to source file ("static").
Unfortunately if you have several files in your library that you want to
share external data/functions without making them visible to user programs,
C has not provided any mechanism for that.  Two solutions are to bundle all
the related sources together in a single file (with the drawback that a
reference to any entry point will pull the whole object file into your
binary image), or to invent names for inter-file use that the user is not
likely to use in his code (e.g., _Q8Q_myfunc() ).

If you have "C with classes" or C++, that provides a superior information-
hiding mechanism.  However, you still have to contend with the two-level
global label scheme that the loader employs.



More information about the Comp.lang.c mailing list