🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #2372

stdarg.h question

#2372
From: John Salmon
Date: Fri, 25 Jan 1991 20:32
53 lines
1891 bytes
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]
Technical Details
Message-ID: <JOHNS.91Jan25123228@haggis.ccsf.caltech.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!munnari.oz.au!uhccux!ames!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!jarthur!nntp-server.caltech.edu!nntp-server!johns

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!munnari.oz.au!uhccux!ames!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!jarthur!nntp-server.caltech.edu!nntp-server!johns
From: johns@haggis.ccsf.caltech.edu (John Salmon)
Newsgroups: comp.std.c
Subject: stdarg.h question
Message-ID: <JOHNS.91Jan25123228@haggis.ccsf.caltech.edu>
Date: 25 Jan 91 20:32:28 GMT
Sender: news@nntp-server.caltech.edu
Distribution: comp
Organization: Caltech Concurrent Supercomputing Facility.
Lines: 53
Nntp-Posting-Host: haggis.ccsf.caltech.edu