Reserved words in C

Ray Butterworth rbutterworth at watmath.UUCP
Wed Jan 7 03:45:44 AEST 1987


In article <5476 at brl-smoke.ARPA>, gwyn at brl-smoke.ARPA (Doug Gwyn ) writes:
> I'm not sure that's what X3J11 intended, but it's what I deduce
> from section 1.6 of the Draft Proposed Standard; however, one
> wonders why "additional library functions" are mentioned if
> they would be so hard to provide (basically, there would have
> to be a header file that redefined the externs as _-names).

The solution used by the C (and B and Pascal) library maintained
here is to have two names for every external (trivial when the
source is in assembler, possibly more difficult if it's in C
(maybe that would be a good use for the "entry" keyword?)).
All library functions that call other library functions do so
by their "other" name.  Thus a user program could define functions
called printf() or write(), while any library functions that need
the standard printf or write for error messages will still get the
standard version, not the user's.  printf is rather obvious and not
likely to be accidentally redefined by a user; there are other
names that aren't so obvious (e.g. BSD's index), and such a scheme
prevents accidents.  If a user really wants to redefine a library
function, he can use its alternate internal name.

It would have been nice if ANSI had required some such scheme.

It would also have been nice if ANSI had defined its standard library
following its own reserved name rule (i.e. a leading underscore).
For instance the stdio functions would have been _printf(),
_putchar(), etc.  For compatibility with existing implementations
a <compat_bsd.h> or <compat_whitesmiths.h> or <compat_KandR.h> or
whatever could have been provided with appropriate defines to map
the names or even the calling sequences.

This would also solve the problem of names such as isascii()
being reserved but undefined.  Any library that now uses or defines
isascii() is in violation of the standard.



More information about the Comp.lang.c mailing list