Abusing the C preprocessor
?
在這里Abusing the C preprocessor(http://psomas.wordpress.com/tag/preprocessor/)看到這個(gè)C語(yǔ)言宏的使用技巧。把示意代碼拷貝出來(lái),稍加修改可以在VS下編譯。
至于其中的原理我就不說(shuō)了,XX后看原文吧。
?
void foo_1(int x){ printf("foo_1 %d\n",x); }
void foo_2(int x,int y){ printf("foo_2 %d %d\n",x,y); }
#define PASTE(a, b) a ## b
#define PASTE2(a, b) PASTE(a, b)
#define NARG_(_9, _8, _7, _6, _5, _4, _3, _2, _1, n, ...) n
#define NARG(...) NARG_(__VA_ARGS__, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define foo1(...) foo_1(__VA_ARGS__)
#define foo2(...) foo_2(__VA_ARGS__)
#define foo(...) PASTE2(foo, NARG(__VA_ARGS__)(__VA_ARGS__))
?
int main(void){
foo(32);
foo(12,23);
return 0;
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/aoaoblogs/archive/2011/11/29/2267034.html
總結(jié)
以上是生活随笔為你收集整理的Abusing the C preprocessor的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: quartus 2操作
- 下一篇: APK反编译以及提取有用信息