Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!spool.mu.edu!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Need help in Message-ID: <6350@goanna.cs.rmit.oz.au> Date: 15 Jun 91 06:01:17 GMT References: <1991Jun12.174326.5390@Veritas.COM> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 35 In article <1991Jun12.174326.5390@Veritas.COM>, tsai@Veritas.COM (Cary Tsai) writes: > Could you C guru tell me why the third ooprint() stmt causes coredump. > I must be missing something in ooprint(). > void ooprint(va_alist) > va_dcl > { > va_list ap; > PFV func; > char *client; > char *foo; > > va_start(ap); > foo = va_arg(ap, char *); > if ((func = va_arg(ap, PFV)) != (PFV) 0) { ^^^^^^ Note: this function ALWAYS tries to access at least two arguments. > ooprint("ooprint", testFunc1, mess1); > ooprint("ooprint", testFunc2, mess2); > ooprint("ooprint"); /* WHY THIS STMT CAUSES CORE-DUMP? */ Why _does_ that statement cause a core dump? Well, WHERE IS THE SECOND ARGUMENT? Failing to supply an argument is not the same as supplying a NULL. I think you mean ooprint("ooprint", (PFV)0); If the function really is as you have presented it, I don't see why you're bothering with varargs at all. It would be simpler just to pass three arguments every time, and to write the 3rd call as ooprint("ooprint", (PFV)0, ""); Better type checking, no worries about varargs -vs- stdargs, &c &c &c. -- Q: What should I know about quicksort? A: That it is *slow*. Q: When should I use it? A: When you have only 256 words of main storage.