Reserved words in C

Karl Heuer karl at haddock.UUCP
Thu Dec 25 07:40:17 AEST 1986


In article <1016 at zeus.UUCP> dant at tekla.tek.com (Dan Tilque) writes:
>I'm fairly new to using C but one of the things I liked about it was the
>small number of reserved words in the language. ... Is this going to change?
>Is C going to become like COBOL?  I certainly hope not.

Even in pre-ANSI C, the problem exists:

[a]  A naive user includes <stdio.h> to declare a FILE.  He doesn't know
     anything about "NULL", and tries to use that name as a local variable:
	register int NULL;	/* NUmber of Long Lines */
     This fails because NULL is a macro defined in that header file.  Hence
     its name must be considered "reserved", even though it's not known to the
     compiler proper.

[b]  A user who has read all the ANSI documents tries to write the following
     (legal) program:
	void write(s) char *s; { printf("%s\n", s); }
	main() { write("Hello, world\n"); return 0; }
     This will fail under most current implementations, because there is a
     library routine call write() which, although not mentioned by the user,
     is nevertheless invoked indirectly through printf().  Thus, every name in
     the standard library must be considered reserved, whether used or not.
     (Note that for this particular example, "write" is *not* part of the ANSI
     standard, so a strictly conforming implementation must not have printf()
     call write().  It may, however, have printf() call _write(), and provide
     a function named write() which also calls _write().)

This is a tough problem in general, and I don't know what the answer is.  (One
approach is the VMS-like notion of having a prefix on everything reserved:
"sys$write()", "mth$cos()", etc.  Ugly, but perhaps necessary.)

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list