macro expansion

Ian Lance Taylor iant@google.com
Wed Sep 1 14:37:00 GMT 2010


Matti Linsu <matti.linsu@yahoo.com> writes:

>> There is a space after 0_start_with_a_number because gcc emits a space
>> whenever necessary to prevent tokens from accidentally pasting together.
>> E.g., a space is required between '+' and '=' in preprocessor output.
>> The test for whether a space is necessary is conservative.
>> 0_start_with_a_number is not an identifier, so the conservative test
>> says that a space is required.
>
> Could you give an example where tokens would accidentally be pasted together?
> I cannot find any case where it would happen.

I implied an example.  Here it is in more detail:

#define P() +
#define E() =
P()E()

The preprocessor must insert a space between the '+' and the '=',
otherwise it will produce the single token '+='.  On the other hand:

#define A() &
P()A()

The preprocessor does not have to preserve that space, because '+&' is
always two tokens, and indeed gcc's preprocessor does not preserve it.

Ian



More information about the Gcc-help mailing list