[英]C++ `ifdef` with concatenation of macros values
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 谢谢
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. 也许如果您描述了您实际想要实现的目标,那么可能会有另一种方式来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.