Redefining keywords (is #define short int legal?)

Henry Spencer henry at utzoo.UUCP
Wed Jan 30 09:57:19 AEST 1985


> ...  Is it legal (by the ANSI standard)
> to treat C keywords specially *in the 'preprocessor'*?  (I quote
> 'preprocessor' because I don't think the standard actually requires it to be
> a separate pass.)

An interesting question.  By a slightly-old draft (my copy of the latest
one isn't handy right now), it would seem that C keywords are, indeed,
not identifiers and thus are ineligible for being #defined.  I don't know
whether this is a feature or an oversight, although I would suspect the
former.  One reason for suspecting it is that the committee was trying
to define the preprocessor commands in such a way that implementation
at the token (as opposed to text-stream) level was straightforward.  The
reason for this is the one you allude to:  the preprocessor is not required
to be a separate pass, and in fact a number of compilers do it in the
scanner.  Life is much simpler if preprocessing doesn't require mapping
tokens back to a string representation.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.lang.c mailing list