你能一步一步解释这个过程吗?

时间:2011-07-18 07:12:59

标签: c++

这是原始代码,我希望使用ivlpp_mainargc通过argv传递所有参数。

static void build_preprocess_command(int e_flag)
{
    ivlpp_main(argc, argv);
    snprintf(tmp, sizeof tmp, "%s%civlpp %s%s -F\"%s\" -f\"%s\" -p\"%s\" ",
               pbase, sep, verbose_flag?" -v":"",
               e_flag?"":" -L", defines_path, source_path,
               compiled_defines_path);    
}

这是我的代码

static void build_preprocess_command(int e_flag)
{
    char  arg0[] = "%s%civlpp";
    char  arg1[] = "%s%s";
    char  arg2[] = "-F\”%s\”";
    char  arg3[] = "-f\”%s\”";
    char  arg4[] = "-p\”%s\”";
    char  arg5[] = "-v";
    char  arg6[] = "-L";
    char **argv[] = { &arg0[0], &arg1[0], &arg2[0], &arg3[0], &arg4[0], &arg5[0], &arg6[0],  NULL };
    int   argc   = 7;//(int)(sizeof(argv) / sizeof(argv[0])) - 1;
    ivlpp_main(argc,argv);
}

1 个答案:

答案 0 :(得分:0)

  

我的代码是否正确? - imon

不应该,

char *argv[] = { ... };  // single pointer array
int argc = sizeof(argv) / sizeof(argv[0]); // to make it less error prone

此外,您应该通过&argv

ivlpp_main(argc,&argv); // assuming ivlpp_main() is like main()