Token-Pasting Operator (##)

Beema, Vishnu (IE10) Vishnu.Beema@Honeywell.com
Wed Mar 24 12:14:00 GMT 2010


Hi I am using ATXmega128A1 controller and AVR studio as developing tool.
I am trying to use Token-Pasting Operator (##).

#define DO1_ON     D, 0
#define DO1_OFF    D, 1

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

#define DO_SET(DO_STATUS)      DO_SET_1(DO_STATUS)
#define DO_CLEAR(DO_STATUS)    DO_CLEAR_1(DO_STATUS)

I want to use below variables

PORTD.OUTSET = PIN0_bm
PORTD.OUTCLR = PIN0_bm

PORTD.OUTSET = PIN1_bm
PORTD.OUTCLR = PIN1_bm

So to replicate as above I am using below macros

DO_SET_1(DO1_ON); 
DO_ CLEAR_1(DO1_ON); 

But I am getting following error  - "error: macro "DO_SET_1" requires 2
arguments, but only 1 given"

Now if I call 

DO_SET(DO1_ON);
DO_ CLEAR(DO1_ON);

The above error is not coming. Now I am getting other error saying
"error: pasting "PORTD" and "." does not give a valid preprocessing
token"

Queries:
1.      By calling DO_SET() how does the error "DO_SET_1" requires 2
arguments, but only 1 given" is removed when DO_SET() is expanding to
DO_SET_1()

2.      Can't "." be used as part of Token-Pasting.

 
Please let me know your comments.

Thanks & Regards
Vishnu



More information about the Gcc-help mailing list