开发者

Weird #define declaration, can't understand to what it expands

I have this #define statement in legacy code I'm inspecting in C.

#开发者_C百科define STEP(x)         case x: STEP ## x : WPAN_Startup_Step = x;

This is a macro to replace cases in a very big switch state machine. I can't understand what's going on in this macro. What does it expand to ?


## does a concatenation, this means that the result will be something like this:

STEP(1)

case 1: STEP1: WPAN_Startup_Step = 1;

or another example:

STEP(v)

case v: STEPv: WPAN_Startup_Step = v;

this macro does not make to much sense to me, since it generates x: STEPx: maybe a usage example would clarify this.

if you want to see the expansion of a macro use: gcc -E program.c

also a good place to learn about macros: http://gcc.gnu.org/onlinedocs/cpp/Macros.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜