-1
あるトークン、
で別のマクロ作品というトークンを連結が、トークンがマクロであるとき、それはしていないようです作業?GCCプリコンパイラマクロ##、<br> 、また、あなたが働くトークンを連結見ることができるように別のマクロ
longNameForaFunction_one(){return 1;}
longNameForaFunction_two(){return 2;}
longNameForaFunction_third(){return 3;}
two(){return 2;}
#define bar two
#define foo(x)(longNameForaFunction_##x())
#define three third
main(){
printf("%d\n",foo(one)); // 1
printf("%d\n",foo(two)); // 2
printf("%d\n",bar()); // 2
// printf("%d\n",foo(three)); // this doesn't work
}
最後の行は、コメントを外すとこのエラーが発生します。
`longNameForaFunction_three」への未定義の参照が
#define three third
は、あなたはそれが動作する前に別のレベルを提供する必要がある理由です何の効果
さらに空白を使用します。 '#define EVALUATOR(x)x'と' #define CONCATENATE(x、y)x ## y'を使い、 '#define foo(x)CONCATENATE(longNameForaFunction_、EVALUATOR(x))'を使ってください。そして、これは重複しています。 –