代码:
/* fun.h */
#ifndef AUTO_INCLUDE #define AUTO_INCLUDE
#define TYPE int #define FUNC swap_i #include __FILE__
#define TYPE char #define FUNC swap_c #include __FILE__
#undef AUTO_INCLUDE #endif
#ifdef AUTO_INCLUDE void FUNC(TYPE *a, TYPE *b) { TYPE tmp; tmp = *a; *a = *b; *b = tmp; } #undef TYPE #undef FUNC #endif
代码:
/* main.c */ #include "fun.h" main() { int i=10,j=20; char a='a',b='b'; swap_i(&i,&j); swap_c(&a,&b); printf("%d %d\n",i,j); printf("%c %c\n",a,b); getchar();
}
在www.google.com/codesearch搜索下#include __FILE__,用这种技巧的代码还真不少。
|