8

Can I achieve something similar to following code:

#define MODULE base
#if defined (MODULE ## _dll)      <-- this should do `#ifdef base_dll`
    ...
#else
    ...
#endif

second line is obviously wrong. Can I do this somehow?

Thanks

graywolf
  • 7,092
  • 7
  • 53
  • 77

1 Answers1

7

I don't think it is possible to check the definition of token-pasted macro like that (at least I don't know the way) but you can do this:

#define JOIN_INTERNAL(a,b) a ## b
#define JOIN(a,b) JOIN_INTERNAL(a,b)

// switch 1/0
#define base_dll 1

#define MODULE base

#if JOIN(MODULE,_dll)
// the base_dll is 1
#else
// the base_dll is 0 or not defined (in MSVC at least)
#endif

Perhaps if you describe what do you actually want to achieve there might be another way to do that.

EmDroid
  • 5,918
  • 18
  • 18