Need help in <varargs.h>
Richard A. O'Keefe
ok at goanna.cs.rmit.oz.au
Sat Jun 15 16:01:17 AEST 1991
In article <1991Jun12.174326.5390 at Veritas.COM>, tsai at 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.
More information about the Comp.lang.c
mailing list