Reserved names in ANSI C

Jeffrey Kegler jeffrey at algor2.UUCP
Sun Jul 2 07:07:51 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).  Since there is only one Ansi Standard and, hopefully, many
>people writing code to that standard, I wish the Committee had found
>way to prevent the C-implementation namespace from growing without bounds.

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.
(That is, you are telling the library programmer, "Quick, think of 130
names nobody else will ever think of")

4) All external names must be distinct, case distinctions not
included, in the first 6 characters, in order to be fully portable.
Whose linker was this, anyway, that we are going to spend the next two
decades wrecking our code for? (Couldn't the ANSI C committee have
found a linker somewhere that was restricted to 5 characters, vowels
not counted?) :-)

The only real solution to this problem is something like the renaming
facility that was allowed in ADA.  That is, suppose you are using one
person's window manager library, and the patented WhatchaMacallit
database.  Both use names all carefully prefixed with WM_ to prevent
conflicts.  The only way to prevent conflicts like this is to license
library writers, which solution is far worse than than (admittedly
nasty) problem.  And here both library writers have tried to be
careful, at the expense of readability.  They left themselves exactly
three characters in which their external names must be distinct.
(They could try numbering them, WM_000, WM_001, etc.) :-)

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).  Or a utility
could be written to convert programs to strictly conforming ones
(portable, very ugly, and a nasty thing to do to the guy who will have
to work with the munged variable names).
-- 

Jeffrey Kegler, President, Algorists,
jeffrey at algor2.UU.NET or uunet!algor2!jeffrey
1762 Wainwright DR, Reston VA 22090



More information about the Comp.std.c mailing list