Path: utzoo!attcan!uunet!munnari.oz.au!bruce!alanf From: alanf@bruce.cs.monash.OZ.AU (Alan Grant Finlay) Newsgroups: comp.lang.c Subject: re-entrant libraries - is C deficient? Message-ID: <3154@bruce.cs.monash.OZ.AU> Date: 2 Oct 90 15:21:42 GMT Organization: Monash Uni. Computer Science, Australia Lines: 26 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. A lot of these procedures call each other so the pointer is popped off and onto the stack all the time. I know popping it off doesn't cost anything but pushing on again does. What I would like to do (and could do in assembly) is to push it on the stack once (i.e. implicitly or explicitly dedicate a register to the task of locating this pointer). I'm sure there are other languages that provide a solution to this problem. For example in Pascal I can have nested procedures (I know this is not quite a solution since the application must be compiled in the scope of the nested procedures - but it is part way to a solution). My question is: have I overlooked something or do I need to descend into assembly language to solve this problem in C (assuming a C compiler has a "base" register, can do without a register or provides some means to know where the stack base is)? I know there are solutions for each particular operating system but I want a techique that can be ported without having to worry about such matters (i.e if all else fails I'll stick with the wasted parameter).