'Pass an array or argptr as parameters to a old varargs (...) function? C++

I have a old varargs(...) function that uses va_list, va_start, va_arg, va_end

cell executeForwards(int id, ...)
{
    if (!g_forwards.isIdValid(id))
        return -1;

    cell params[FORWARD_MAX_PARAMS];
    
    int paramsNum = g_forwards.getParamsNum(id);
    
    va_list argptr;
    va_start(argptr, id);

    ForwardParam param_type;
    
    for (int i = 0; i < paramsNum && i < FORWARD_MAX_PARAMS; ++i)
    {
        param_type = g_forwards.getParamType(id, i);
        if (param_type == FP_FLOAT)
        {
            REAL tmp = (REAL)va_arg(argptr, double);            // floats get converted to doubles
            params[i] = amx_ftoc(tmp);
        }
        else if(param_type == FP_FLOAT_BYREF)
        {
            REAL *tmp = reinterpret_cast<REAL *>(va_arg(argptr, double*));
            params[i] = reinterpret_cast<cell>(tmp);
        }
        else if(param_type == FP_CELL_BYREF)
        {
            cell *tmp = reinterpret_cast<cell *>(va_arg(argptr, cell*));
            params[i] = reinterpret_cast<cell>(tmp);
        }
        else
            params[i] = (cell)va_arg(argptr, cell);
    }
    
    va_end(argptr);
    
    return g_forwards.executeForwards(id, params);
}

For some reason I need to push the parameters dynamically to this function, for example by using an array or something, Is that possible in C++?

example code:

va_list argptr;
va_push(argptr, 100);
va_push(argptr, 2.22f);
va_push(argptr, 300);
executeForwards(0, argptr);

Notice: I cannot modify the content of this function (executeForwards)

c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source