simpson@trwarcadia.uucp (03/22/89)
Can anyone tell me the magic incantation to call varargs twice on a Sun 3/60?
I don't know the format of the stack and I don't have a Motorola manual.
Please don't flame me for non-portability. What I want to do is this
(which only gives me the first argument):
#include <stdio.h>
#include <varargs.h>
b(va_alist)
va_dcl
{
char *s1, *s2;
va_list ap;
va_start(ap);
s1 = va_arg(ap, char *);
s2 = va_arg(ap, char *);
printf("b(): s1=%s, s2=%s\n", s1, s2);
va_end(ap);
}
/* a() calls b() */
a(va_alist)
va_dcl
{
char *s1, *s2;
va_list ap;
va_start(ap);
s1 = va_arg(ap, char *);
s2 = va_arg(ap, char *);
printf("a(): s1=%s, s2=%s\n", s1, s2);
b(va_alist);
va_end(ap);
}
main()
{
static char *s1 = "Hello";
static char *s2 = "There";
a(s1, s2);
exit(0);
}
Scott Simpson
TRW Space and Defense Sector
oberon!trwarcadia!simpson (UUCP)
trwarcadia!simpson@oberon.usc.edu (Internet)chris@mimsy.UUCP (Chris Torek) (03/22/89)
In article <1698@spp2.UUCP> simpson@trwarcadia.uucp writes: >Can anyone tell me the magic incantation to call varargs twice on a Sun 3/60? There is no such incantation; what you are trying to do is, in general, impossible. >b(va_alist) >va_dcl >{ ... >} > >/* a() calls b() */ >a(va_alist) >va_dcl >{ ... > b(va_alist); What you need to do instead (which is not only possible, but even portable) is this: b(va_alist) va_dcl { va_list ap; va_start(ap); vb(ap); va_end(ap); } vb(ap) va_list ap; { ... } a(va_alist) va_dcl { va_lits ap; va_start(ap); vb(ap); ... This is why v*printf() exist. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris