How to get address of va_arg?

Posted by lionbest on Stack Overflow See other posts from Stack Overflow or by lionbest
Published on 2010-04-19T21:00:56Z Indexed on 2010/04/19 21:03 UTC
Read the original article Hit count: 248

Filed under:
|

I hack some old C API and i got a compile error with the following code:

void OP_Exec( OP* op , ... )
{
    int i;
    va_list vl;
    va_start(vl,op);
    for( i = 0; i < op->param_count; ++i )
    {
        switch( op->param_type[i] )
        {
            case OP_PCHAR:
                op->param_buffer[i] = va_arg(vl,char*); // ok it works
            break;
            case OP_INT:
                op->param_buffer[i] = &va_arg(vl,int); // error here
            break;
            // ... more here
        }
    }
    op->pexec(op);
    va_end(vl);
}

The error with gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) was:

 main.c|55|error: lvalue required as unary ‘&’ operand

So why exactly it's not possible here to get a pointer to argument?

How to fix it? This code is executed very often with different OP*, so i prefer to not allocate extra memory.

Is it possible to iterate over va_list knowing only the size of arguments?

© Stack Overflow or respective owner

Related posts about c

    Related posts about va-arg