0

Possible Duplicate:
C preprocessor and concatenation

I have the macro

#define BUS B

I want to make macro BUS_PORT that expands to PORTB.

I did following:

#define BUS_PORT PORT ## BUS

But BUS_PORT expands to PORTBUS. What I did wrong? How to make it right?

4

1 回答 1

1

As explained in this answer, you need an extra level of indirection. E.g.

#define BUS B
#define PASTER(x,y) x ## y
#define EVALUATOR(x,y) PASTER(x,y)
#define BUS_PORT EVALUATOR(PORT, BUS)
于 2012-12-18T18:31:10.607 回答