lin-club  

passing variable number of arguments to a function

Amir Abiri
Fri, 03 Aug 2001 15:14:35 -0700

Does anyone know how to pass a variable number of arguments to a function ?
More specificly:
void a(char *format, ...)
{
    /*
    some bullshit stuff
    */
    // and now i want to pass all the optional parameters a() got to
printf() :
    printf(format, /* What goes here ? */);
}

at the moment all i have is using assembler ( Visual C++ 6.0):
__asm
{
    mov eax, <value for integers, address for strings>
    push eax
    .
    . repeat as needed
    .
    move eax, offset format
    push eax
    call printf
    pop ebx
    .
    . Repeat the same number of times that we poped.
    .
}

This is off course ugly and bugs prone (crash count:3 so far, and counting )
i'm want to know if there is some more elegant and less bug prone solution ?

--
foreach $task in (</etc/current_workplace/tasks); do
    find_someone_to_do_it --default=amir 2> /dev/amir; done