[comp.std.c] stdarg.h question

johns@haggis.ccsf.caltech.edu (John Salmon) (01/26/91)

If a function uses a va_list, and passes it as an argument to
more than one other function, then do the va_args accumulate
or are they "restarted" after each return?  Perhaps this is
best stated as a "what should the following program produce?"
After the first call call to apfunc returns, is it required
that varfunc:ap reflect the fact that va_arg has been called once?
In other words, should this program print 
"arg1 12, arg2 43\n"
or should it print
"arg1 12 arg2 12\n"
or is its behavior undefined or ...

Thanks,
John Salmon
johns@delilah.ccsf.caltech.edu
johns@caltech.bitnet

--------------cut here ------------
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>

void varfunc(int dummy, ...);
int apfunc(va_list apsub);

main(int argc, char **argv){
    
    varfunc(0, 12, 43);
    exit(0);
}

void varfunc(int dummy, ...){
    va_list ap;
    int arg1, arg2;

    va_start(ap, dummy);
    arg1 = apfunc(ap);
    arg2 = apfunc(ap);
    printf("arg1 %d, arg2 %d\n", arg1, arg2);
    va_end(ap);
}

int apfunc(va_list apsub){
    return va_arg(apsub, int);
}


--
John Salmon		 Internet: johns@delilah.ccsf.caltech.edu
206-49 Caltech		 UUCP: johns%delilah.ccsf.caltech.edu@uunet.uu.net
Pasadena, CA 91125 USA	 Bitnet: johns@caltech.bitnet
(818)356-2907		 delilah.ccsf.caltech.edu=[131.215.145.137]