Token-Pasting Operator (##)

John (Eljay) Love-Jensen eljay@adobe.com
Wed Mar 24 13:08:00 GMT 2010


Hi Vishnu,

To use token pasting preprocessor operator, you must be pasting a token and a token to form a single new token.  You cannot be pasting two token together.

#define DO_SET_1(X, Y)      PORT ## X ##.OUTSET = PIN ## Y ## _bm
DO_SET_1(D, 0);

I am going to list out the expansion with one token per line:

PORTD
.
OUTSET
=
PIN0_bm

Notice in your macro you have this token pasting:

X ## .

You cannot token paste X substitution argument conjoined to . (dot).  That does not form a token, it forms two tokens.

If you change your #define macro to:

#define DO_SET_1(X, Y)      PORT ## X .OUTSET = PIN ## Y ## _bm

Then you will no longer be trying to form an invalid token paste between X and . (dot).

Sincerely,
--Eljay



More information about the Gcc-help mailing list