problem with varargs
Srinivas Madhur
sm at gator.cacs.usl.edu
Mon Mar 26 10:25:45 AEST 1990
Hi netters!
I am having a problem with varargs (both on Sun 4.0 and 4.3BSD).
The example program given in the man page shows that after all
the parameters passed are read, next time va_arg is called, the
return value will be NULL which can be used as a sentinel.
I am getting the NULL value if there is *no other variable*
defined after the actual parameter or if the paramter passed to
the function is global. Is there any known problem with varargs
in SunOS and 4.3BSD or am I missing something obvious? If this is
a problem, what is the fix?
Please respond to me via email as I rarely read this group!
Any help would be greatly appreciated!
I am enclosing a sample program.
----------------cut here---------------------------------------
#include <varargs.h>
#include <stdio.h>
main()
{
static char ppp[] = "message";
char *next = "error";
foo(ppp); <---- calling foo with only ppp as param
prints "message error"
}
foo(va_alist)
va_dcl
{
va_list ap;
char * ptr;
va_start(ap);
while ((ptr = va_arg(ap, char *)) != NULL)
printf("%s ", ptr);
va_end(ap);
printf("\n");
}
------------------------cut here--------------------------------
--
Srinivas Madhur
sm at gator.cacs.usl.edu
sm at cacs.usl.edu
.!dalsqnt!gator!sm
More information about the Comp.unix.questions
mailing list