#define STR1 "s"
#define STR2 "1"
#define STR3 STR1 ## STR2
Run Code Online (Sandbox Code Playgroud)
是否有可能连接STR3 =="s1"?您可以通过将args传递给另一个宏函数来完成此操作.但是有直接的方法吗?
在标准C或GNU扩展中有什么方法可以将内容附加到宏定义中吗? 例如,给定一个宏定义为
#define List foo bar
可以追加,bas以便它List扩展,就像我定义它一样
#define List foo bar bas?
我希望我能做到这样的事情:
#define List foo bar bas
#define List_ Expand(List)
#undef List
#define List Expand(List_) quux
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何定义Expand()宏,所以它会做我想要的.
动机: 我在这些方面玩歧视/标记的工会:
struct quux_foo { int x; };
struct quux_bar { char *s; };
struct quux_bas { void *p; };
enum quux_type {quux_foo, quux_bar, quux_bas};
struct quux {
enum quux_type type;
union {
struct quux_foo foo;
struct quux_bar bar;
struct quux_bas bas;
} t; …Run Code Online (Sandbox Code Playgroud)