The Preprocessor and tokens

Norman Diamond diamond at jit345.swstokyo.dec.com
Fri Mar 29 17:31:02 AEST 1991


In article <3140 at wyse.wyse.com> cmills at wyse.UUCP (Chris Mills x2427 dept203) writes:
>In article <1991Mar27.033525.21697 at tkou02.enet.dec.com> diamond at jit345.enet@tkou02.enet.dec.com (Norman Diamond) writes:
>>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.
>What do you mean the preprocessor can do whatever it wants?  If the standard
>forbids the expansions of the macros, then it can't do what I want, right?

The PREPROCESSOR is not allowed to do this expansion.  AFTER preprocessing,
the PROCESSOR must give at least one diagnostic.  The PROCESSOR is then
allowed to proceed as it likes, including, uh, repreprocessing.

Of course, the processor does not really have to break out a separate
preprocessor step; it only has to behave as though the phases of translation
occured in the standard order.

>Actually, since I'm deliberately trying to be obfuscated, I'd like
>#include <stdio.h>
>int N;
>#define N 3
>void main(argc, argv) char **argv; { printf("%d\n", 0x7e+N); }
>to print 254 instead of 257 consistantly.

Not from ANSI 1989 C.

>As my newfound understanding goes, the preproc. will see "0x73+N" as one
>token and will not expand "N",

Yes.

>and the compiler will see it as three, right?

No.  The compiler will see it as one, issue at least one diagnostic, and
then do whatever it wishes (including possibly converting it to three).

>>RTFS.
>Love to.  Can't justify the cost of TFS for the occasional oddity like this.

If you can't justify $50.00, then you can't afford to use net bandwidth
on it either.

>By the way, does L"string" work the same way?  Does the preproc. see this as
>one token, or two,

One.

>and is Q"string" also a preproc token?

No.  For consistency it should have been (sarcasm here).

>Does anybody actually use these things?

People have actually used strings with multibyte characters in them for
over 10 years.  The L"..." syntax was (to the best of my knowledge) an ANSI
invention and not previously used.  At least this one did not break working
programs.
--
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