Need help in <varargs.h>

Cary Tsai tsai at Veritas.COM
Thu Jun 13 03:43:26 AEST 1991


Could you C guru tell me why the third ooprint() stmt causes coredump.
I must be missing something in ooprint().
Compile and execute 'a.out'. You'll get 'flag is on', 'flag is off' and
...(coredump) or any bus error message.

/*	help ....
*/
#include <stdio.h>
#include <varargs.h>

typedef	void	(*PFV)();

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) {
		if ((client = va_arg(ap, char *)) != (char *) 0)
			func(client);
	}
	va_end(ap);
}

void testFunc1(testData)
char	*testData;
{
	if (testData && *testData)
		puts(testData);
}

void testFunc2(testData)
char	*testData;
{
	if (testData && *testData)
		puts(testData);
}

main()
{
	static	char	*mess1 = "flag is on";
	static  char	*mess2 = "flag is off";

	ooprint("ooprint", testFunc1, mess1);
	ooprint("ooprint", testFunc2, mess2);
	ooprint("ooprint"); /* WHY THIS STMT CAUSES CORE-DUMP? */
}

/* end of help ... */

You help and information would be appreciated.



More information about the Comp.lang.c mailing list