Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!randvax!segue!jim From: jim@segue.segue.com (Jim Balter) Newsgroups: comp.unix.internals Subject: Re: Shared Lib Question (ISC) Message-ID: <7494@segue.segue.com> Date: 12 May 91 12:50:06 GMT References: <276@rwing.UUCP> <162@titccy.cc.titech.ac.jp> <19252@rpp386.cactus.org> Reply-To: jim@segue.segue.com (Jim Balter) Organization: Segue Software, Inc. - Santa Monica, CA. +1-213-453-2161 Lines: 26 In article kre@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.