开发者

Force Whitespace in C Macro?

I've got the following Macro to define a new function following a special naming scheme:

#define CREATE_HOOK_STUB( func ) void ##func_STUB() { /* some code*/ }

However, the preprocessor always concatenates void and ##func_STUB but I obviously want it to preserve the whitespace at tha开发者_运维问答t position.

I know that I could just prepend some string to ##func_STUB, but this is not what I want. How would I solve this?


I think what you really want is closer to:

#define CREATE_HOOK_STUB( func ) void func##_STUB() { /* some code*/ }

But you should also look at this linked SO answer which has some additional details on the behavior of the token pasting operator:

One thing to be aware of when you're using the token-paste ('##') or stringizing ('#') preprocessing operators is that you have to use an extra level of indirection for them to work properly in all cases.

If you don't do this and the items passed to the token-pasting operator are macros themselves, you'll get results that are probably not what you want...

  • link: What are the applications of the ## preprocessor operator and gotchas to consider?
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜