re-entrant libraries - is C deficient?

Larry Hastings funkstr at ucscb.UCSC.EDU
Wed Oct 3 06:17:02 AEST 1990


+-In article <3154 at bruce.cs.monash.OZ.AU>,
| alanf at bruce.cs.monash.OZ.AU (Alan Grant Finlay) wrote:
|
| I am writing a library of C procedures which need access to a global 
| data structure.  I wish to write them in a portable manner (i.e. even
| outside UNIX) and to be re-entrant.
| 
| Currently I am doing this by having a compulsary first parameter to all
| the procedures which is a pointer to the global data structure (apart from
| one procedure which allocates this data structure and returns the pointer).
| This is fine but the inefficiency annoys me.
|
+----------

First of all, I'm assuming that this global data structure is read from,
not written to.  (Otherwise, it could never be reentrant...)

Second of all, why not simply model it exactly like it really is --
global data?  If it's never written to, you don't need to worry about
other copies of the code trashing it when you weren't looking.  Or, if you
must use a pointer to point to it, have a global pointer.

There's nothing wrong, inelegant, or even non re-entrant to use global
read-only static data.  For instance, the functions (and macros) in <ctype.h>
are considered reentrant, and yet most implementations use a static table
for the isalpha(), iscntrl(), isascii() (and so on) macros.
--
larry hastings, the galactic funkster, funkstr at ucscb.ucsc.edu

I don't speak for Knowledge Dynamics or UC Santa Cruz, nor do they speak for me

The 4th law of Robotics (courtesy of Lore Shoberg):
"A robot must encourage proper dental hygiene, except where such encouragement
 would interfere with the 0th, 1st, 2nd, and 3rd laws."



More information about the Comp.lang.c mailing list