varargs question

ark at alice.UUCP ark at alice.UUCP
Sat Jul 16 10:28:39 AEST 1988


In article <161 at neti1.uucp>, bdr at neti1.UUCP writes:
> I am writing a function which, ideally, would take an optional
> argument which would be a pointer to a function which returns a
> pointer to a char.  I am using a non-ansi <varargs.h> type compiler.
> My code looks something like:
 

> 	char	*(*func)();	/* local variable to hold pointer */
 	...
> 	func = va_arg(ap, char *(*)());
 
> Unfortunately, va_arg turns the cast into something like:
 
> 	(char *(*)() *) ...
 
> instead of the desired:
 
> 	(char *(**)() ) ...
 
Yes indeed.  Sorry about that -- the preprocessor is awfully
literal-minded.  Do it this way:

	typedef *(*MYPTR)();
	...
	MYPTR func;
	...
	func = va_arg(ap,MYPTR);



More information about the Comp.lang.c mailing list