Path: utzoo!attcan!uunet!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!apple!agate!darkstar!ucscb.UCSC.EDU!funkstr From: funkstr@ucscb.UCSC.EDU (Larry Hastings) Newsgroups: comp.lang.c Subject: Re: re-entrant libraries - is C deficient? Message-ID: <7426@darkstar.ucsc.edu> Date: 2 Oct 90 20:17:02 GMT References: <3154@bruce.cs.monash.OZ.AU> Sender: usenet@darkstar.ucsc.edu Organization: Knowledge Dynamics Corporation Lines: 35 +-In article <3154@bruce.cs.monash.OZ.AU>, | alanf@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 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@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."