开发者

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

开发者 https://www.devze.com 2023-04-11 17:34 出处:网络
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;

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

精彩评论

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

关注公众号