views:

89

answers:

1

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 that 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?

+6  A: 

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...

Michael Burr
Thanks..dumb error :)
jn_