我的问题vsprintf
是我无法直接获取输入参数,我必须先逐个获取输入,并将它们保存在void**
中,然后将此void**
传递给vsprintf()
,这对Windows来说都很好,但是当我来64位linux,gcc无法编译,因为它不允许从void**
转换为va_list
,有没有人可以给我一些帮助,我应该如何在Linux下做到这一点?在GCC中动态创建va_list - 可以完成吗?
我可以在GCC中动态创建va_list吗?
void getInputArgs(char* str, char* format, ...)
{
va_list args;
va_start(args, format);
vsprintf(str, format, args);
va_end(args);
}
void process(void)
{
char s[256];
double tempValue;
char * tempString = NULL;
void ** args_ptr = NULL;
ArgFormatType format; //defined in the lib I used in the code
int numOfArgs = GetNumInputArgs(); // library func used in my code
if(numOfArgs>1)
{
args_ptr = (void**) malloc(sizeof(char)*(numOfArgs-1));
for(i=2; i<numOfArgs; i++)
{
format = GetArgType(); //library funcs
switch(format)
{
case ArgType_double:
CopyInDoubleArg(i, TRUE, &tempValue); //lib func
args_ptr[i-2] = (void*) (int)tempValue;
break;
case ArgType_char:
args_ptr[i-2]=NULL;
AllocInCharArg(i, TRUE, &tempString); //lib func
args_ptr[i-2]= tempString;
break;
}
}
}
getInputArgs(s, formatString, (va_list) args_ptr); //Here
// is the location where gcc cannot compile,
// Can I and how if I can create a va_list myself?
}
[vsprintf,使用sprintf获取输入?]的可能重复?(http://stackoverflow.com/questions/11693448/vsprintf-using-sprintf-to-get-inputs) – 2012-07-27 20:32:02
它不是重复的,因为它在这里GCC特有的。 – 2012-07-27 22:45:25
这个问题和[SO 11693448](http://stackoverflow.com/q/11693448)是非常密切相关的,虽然它们并不完全重复。 – 2012-07-27 23:41:02