Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!samsung!rex!rouge!gator.cacs.usl.edu From: sm@gator.cacs.usl.edu (Srinivas Madhur) Newsgroups: comp.unix.questions Subject: problem with varargs Keywords: varargs, SunOS Message-ID: <5810@rouge.usl.edu> Date: 26 Mar 90 00:25:45 GMT Sender: anon@rouge.usl.edu Organization: The Center for Advanced Computer Studies, USL Lines: 48 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 #include 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@gator.cacs.usl.edu sm@cacs.usl.edu .!dalsqnt!gator!sm