在GCC中动态创建va_list-可以完成吗? [英] creating va_list dynamically in GCC - can it be done?

查看:196
本文介绍了在GCC中动态创建va_list-可以完成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对vsprintf的问题是我无法直接获取输入参数,我必须首先逐个获取输入并将其保存在void**中,然后将此void**传递给vsprintf(),这就是全部适用于Windows,但是当我使用64位linux时,gcc无法编译,因为不允许将其从void**转换为va_list,有没有人可以给我一些帮助,我应该如何在linux下执行此操作?

my problem with vsprintf is that I can not obtain input arguments directly, I have to first get inputs one by one and save them in void**, then pass this void** to vsprintf(), it is all fine for windows, but when I come to 64bit linux, gcc cannot compile because it is not allowed to convert from void** to va_list, Is there anyone that can give me some help how I should do this under linux?

我可以在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?
}

推荐答案

我尝试使用libffi,如其他地方提到的那样,它可以正常工作. 以下是链接,希望它可以帮助其他有类似问题的人. 再次感谢您给我的所有帮助!

I have tried using libffi as mentioned somewhere else and it works. Here below is the link , hope it can help others with similar issues. Thanks again for all help I got here!

链接: http://www.atmark-techno.com/~yashi/libffi.html-给出了简单的例子 http://www.swig.org/Doc1.3/Varargs.html -printf()和其他示例

Link: http://www.atmark-techno.com/~yashi/libffi.html -- simple example given http://www.swig.org/Doc1.3/Varargs.html -- printf() and other examples given

这篇关于在GCC中动态创建va_list-可以完成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆