draft ANSI standard: Is a quote a valid preprocessor-token?
John Gilmore
gnu at hoptoad.uucp
Fri Jan 2 13:20:19 AEST 1987
In article <1971 at emory.UUCP>, arnold at emory.UUCP writes:
> #define CTRL(X) (' ## X ## ' & 037) /* ascii only */
> ...uses the token concatenation operator to produce the character
> constant....
> I am sure someone will correct me if I am wrong.
I thought he was wrong, but I looked again at the standard. I didn't
believe that a single quote would be considered a preprocessing token;
I figured it would parse as
#define CTRL(X) (string & 037)
where string is: ' ## X ## '
(Of course multiple character '...' constants are legal in the draft
proposed standard, but let's not get off the track...) The definition
of preprocessor-token is (pg 74, sec 3.8):
preprocessing-token:
header-name (only within a #include directive)
identifier
constant
string-literal
operator
punctuator
each non-white-space character that cannot be one of the above
Aha! Since a lone quote is not any of the above, it must be one of those
"each non white space characters", and it must be a preprocessing-token.
Right?
Phooey. There should be specific instructions in the standard on
lexical analysis of C programs, e.g. an algorithm for parsing, rather
than this vague English rubbish. This applies to section 2.1.1.2
("The source file is decomposed into preprocessing tokens...") too.
I can see my source files slowly decomposing in there now...
--
John Gilmore {sun,ptsfa,lll-crg,ihnp4}!hoptoad!gnu gnu at ingres.berkeley.edu
I forsee a day when there are two kinds of C compilers: standard ones and
useful ones ... just like Pascal and Fortran. Are we making progress yet?
-- ASC:GUTHERY%slb-test.csnet
More information about the Comp.lang.c
mailing list