-1
토큰의 작품을 연결 볼 수 있듯이,
또한 토큰 다른 매크로 작동되고,
하지만 토큰이 매크로 경우는하지 않는 것이다 토큰을 연결하여 작업?GCC 프리 D 파일러 매크로 ##, 다른 매크로
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))'를 사용하십시오. 그리고 이것은 중복입니다. –