宏是否可以只擴展一次?在以下示例中,MYCONCAT擴展為func_1(10). 我希望它擴展到func_BAR(10).
#define BAR 1 // included from a file I cannot change
#define FOO BAR
#define MYCONCAT2(c) func_ ## c
#define MYCONCAT(c, x) MYCONCAT2(c)(x)
MYCONCAT(FOO, 10) // is 'func_1(10)', but I want it to be 'func_BAR(10)'
uj5u.com熱心網友回復:
宏是否可以只擴展一次?
不,不能部分擴展宏。
uj5u.com熱心網友回復:
包含BAR僅在最后使用的位置之后定義的檔案MYCONCAT(擴展為BAR),而不是在它之前。
uj5u.com熱心網友回復:
只需更改#define BAR為#define _BARand 并洗掉_from func。
#define BAR 1 // included from a file I cannot change
#define FOO _BAR
#define MYCONCAT2(c) func ## c
#define MYCONCAT(c, x) MYCONCAT2(c)(x)
MYCONCAT(FOO, 10) // 'func_BAR(10)'
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/364041.html
