Shared Lib Question (ISC)

Jim Balter jim at segue.segue.com
Sun May 12 22:50:06 AEST 1991


In article <kre.673798776 at mundamutti.cs.mu.OZ.AU> kre at cs.mu.oz.au (Robert Elz) writes:
>>Were the code in the C library pure, shared libraries would
>>be extremely simple to implement.
>
>True, they'd also be close to useless.

Nah.  If every library routine took a pointer argument that was a handle for
the data area, the library could trivially be pure.  You could even write
internal versions that take the handle and external versions (with the familiar
names and arguments) that don't but pick it up from a global and pass it and
all their arguments to the internal routines.  Voila, you have pure library
routines compatible with the current C library interface.  The internal
routines would be just like the current routines except that, instead of using
globals, they would use members of a structure, an instance of which would be
pointed to by the handle.

There's generally a cost for the extra call level, although on architectures
with lots of registers the handle could be loaded into one register and never
changed, and the internal library routines could be called directly (or even
vectored through the handle) given compiler support for accessing the register.


Since it is trivial to turn a routine that uses globals into one that doesn't
by adding an argument, it is silly to say that such routines are "close to
useless".  On the other hand, if "pure" means "has no side effects", then
we are talking about Functional Programming, which is a whole other subject.



More information about the Comp.unix.internals mailing list