[net.lang.c] Redefining keywords

geoff@desint.UUCP (Geoff Kuenning) (01/22/85)

Having the good fortune [:-)] to port a program to a DG C compiler, I carefully
ran it through lint first.  Among other things, I added a whole bunch of
stuff like the following to keep lint happy:

    (void) strcpy (buf, pathname);

When I got it to the DG, I was pleased to discover it understood the void
type.  I was less pleased to learn that it refused to accept the above
construct.  No problem, though, right?  You just do the old reliable

    #define void int

and all becomes well.  Only, the DG C compiler disagrees.  It gave me an
error message on the above line.  Seems that the preprocessor is integrated,
and refuses to allow you to redefine keywords.  It wasn't hard to work around
(just replace all void's with VOID's, and #define VOID void on intelligent
compilers), but it brings up a question.  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.)
-- 

	Geoff Kuenning
	...!ihnp4!trwrb!desint!geoff

henry@utzoo.UUCP (Henry Spencer) (01/30/85)

> ...  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

jim@ISM780B.UUCP (02/07/85)

One amusing thing about Reiser's cpp is that preprocessor keywords
can be defined to or from.  Thus

#define spew include
#spew "crap"
#define if include
#if "crud"

yields

3: Can't find include file crap
5: Can't find include file crud

-- Jim Balter, INTERACTIVE Systems (ima!jim)