Sidebar on name-hiding (was Reserved names in ANSI C)

David Collier-Brown davecb at yunexus.UUCP
Tue Jul 4 23:17:10 AEST 1989


In article <321 at mountn.dec.com> minow at mountn.UUCP (Martin Minow) writes:
| I continue to have difficulty writing transportable programs when
| well-meaning implementors use useful words (such as "line" in one
| vendor's Macintosh C library).

jeffrey at algor2.UUCP (Jeffrey Kegler) writes:
| We have a number of worthwhile but conflicting goals involved here.
| 1) All libraries should use nice, easy to remember names.
| 2) No libraries should use any name any application programmer might
| want to use.  (Presumably this includes all the nice, easy to remember
| ones.)
| 3) No library should use a name another library is likely to use.
[...]
| The only real solution to this problem is something like the renaming
| facility that was allowed in ADA. 

  Actually the renaming scheme predates Ada (and Unix!).  It was based
on the theory that you needed two things to manage the namespace
explosion/pollution problem.
	1) a set of search rules or search lists for the linker
	   (easy now, not so easy in the V6 era!)
	2) a facility to "bind" names in linkable files.

  The latter is non-obvious (indeed the sufficiency of the scheme isn't
obvious at first encounter, either).  
  A "binder" is a program which takes a list of .o files and the
names that they should export, and creates a new .o from that.

  In the simple case, it produces exactly the same effect as "cat"ing
all the source files together and declaring all non-interface function
static.
  Or one can write an interface which effectively renames the
functions and bind that to the existing .o.
  It can even be used (twice) to insert a new, identically-named
function in to replace say, "fwrite", while calling the real fwrite
invisibly down in its guts.

   Why don't we have such a thing?  Well, they can be hard to write,
because you have to know the .o format like the back of your hand.
(I've written exactly one, and it depended on a bug in the linker I was
targeted to, so all I had to do was delete SYMDEF records (:-)).

| The renaming could be implemented as a utility that mungs object files
| (semi-portable), or as an input file to the loader (completely
| unportable) or via pragmas (completely unportable).  

   They're partially portable, as they depend on the .o format, not the
actual format of the machine code. As long as someone has ported the
compiler & linker, the stock binder can be recompiled with a few -DXYZZY's

--dave (just guess where they came from!) c-b
-- 
David Collier-Brown,  | davecb at yunexus, ...!yunexus!davecb or
72 Abitibi Ave.,      | {toronto area...}lethe!dave 
Willowdale, Ontario,  | Joyce C-B:
CANADA. 223-8968      |    He's so smart he's dumb.



More information about the Comp.std.c mailing list