Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!ncar!tank!shamash!nic.MR.NET!thor!agnes!mackenzi From: mackenzi@agnes.uucp (David MacKenzie) Newsgroups: comp.lang.c Subject: passing variable numbers of arguments Message-ID: <899@thor.stolaf.edu> Date: 7 Jan 89 05:20:11 GMT Sender: news@thor.stolaf.edu Reply-To: edf@rocky2.rockefeller.edu Distribution: na Organization: Environmental Defense Fund Lines: 80 The following program produces unexpected results: #include main () { printf ("foo:\n"); foo (1, 2, 3, 0); printf ("bar:\n"); bar (4, 5, 6, 0); } foo (va_alist) va_dcl { bar (va_alist); } bar (va_alist) va_dcl { va_list list; int i; va_start (list); while (i = va_arg (list, int)) printf ("%d\n", i); va_end (list); } On a 68000 machine, it produces: foo: 1 14679744 160 1 2 3 bar: 4 5 6 and on a VAX it produces: foo: 1 bar: 4 5 6 whereas the output I wanted is: foo: 1 2 3 bar: 4 5 6 In other words, if I call bar () directly, it works, but if I call it via foo (), it breaks, in an implementation-dependant way, no less. Why? Is there anyway to get this to work? The problem has arisen as I am trying to port Allan Holub's (DDJ, April 1988) integer-only printf from to . printf, sprintf, and fprintf are small little functions that call a function called idoprnt and both the small front-end functions and idoprnt seem to need to accept a variable number of arguments. David MacKenzie edf@rocky2.rockefeller.edu --- p.s. I post from this account because inews doesn't seem to be able to post new articles on rocky2 -- very strange, since it can post followups just fine.