我的問題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