使用 BOOST
#include <stdio.h>
#include <string.h>
#include <boost/preprocessor.hpp>
#define GEN_DEC(x, i, name) char* BOOST_PP_CAT(name, i);
#define GEN_FUNC(x, i, name) strcpy(argv[i], BOOST_PP_CAT(name, i));
int main(int argc, char* argv[]){
BOOST_PP_REPEAT(10,GEN_DEC,arg)
BOOST_PP_REPEAT(10,GEN_FUNC,arg)
return 0;
}
命令行
>gcc -I c:\boost_1_48_0 test.c
查看
>gcc -I c:\boost_1_48_0 test.c -E
输出样本
int main(int argc, char* argv[]){
char* arg0; char* arg1; char* arg2; char* arg3; char* arg4; char* arg5; char* ar
g6; char* arg7; char* arg8; char* arg9;
strcpy(argv[0], arg0); strcpy(argv[1], arg1); strcpy(argv[2], arg2); strcpy(argv
[3], arg3); strcpy(argv[4], arg4); strcpy(argv[5], arg5); strcpy(argv[6], arg6);
strcpy(argv[7], arg7); strcpy(argv[8], arg8); strcpy(argv[9], arg9);
return 0;
}