The Preprocessor and tokens

Norman Diamond diamond at jit345.swstokyo.dec.com
Wed Mar 27 13:35:25 AEST 1991


In article <3137 at wyse.wyse.com> cmills at wyse.wyse.com () writes:

>what does the Standard say about constuctions like these:
>#define _	+ 42
>int j = 6_;
>#define N	42
>int k = 0x7e+N;

The standard forbids those macros from being expanded.
However, since your program violates the ANSI syntax, the processor may do
whatever it wishes, as long as it produces at least one diagnostic.  It
could, if it wishes, give a warning and then do what you asked for.

>Is there a good reason for this (other than the preprocessor is a little
>easier to write if you define [0-9][0-9a-zA-Z_]* as a token)?

No, there is no good reason for it.  The possible reason, which you suggest,
also falls pretty far short of being a good one.  There is no good reason.

>I was under the impression that the preprocessor and the compiler agreed
>on what constituted a token...

The standard specifically distinguishes preprocessor-tokens from tokens.
RTFS.

>Do K&R compilers do it any differently?

Usually.  The standard broke some working, valid, code this time.
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.



More information about the Comp.std.c mailing list