stdarg.h question

John Salmon johns at haggis.ccsf.caltech.edu
Sat Jan 26 07:32:28 AEST 1991


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 at delilah.ccsf.caltech.edu
johns at 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 at delilah.ccsf.caltech.edu
206-49 Caltech		 UUCP: johns%delilah.ccsf.caltech.edu at uunet.uu.net
Pasadena, CA 91125 USA	 Bitnet: johns at caltech.bitnet
(818)356-2907		 delilah.ccsf.caltech.edu=[131.215.145.137]



More information about the Comp.std.c mailing list