[comp.lang.c] varargs question

bdr@neti1.uucp (Brian Renaud) (07/13/88)

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 *(**)() ) ...

Am I (quite likely) just making a dumb error here?  If not, is there
some portable workaround to deal with this?

-- 
Brian Renaud      bdr%huron.uucp@umix.cc.umich.edu
Huron Systems     {umix,neti2}!huron!bdr

ark@alice.UUCP (07/16/88)

In article <161@neti1.uucp>, bdr@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);

tps@chem.ucsd.edu (Tom Stockfisch) (07/16/88)

In article <161@neti1.uucp> bdr@neti1.uucp (Brian Renaud) writes:
X...  I am using a non-ansi <varargs.h> type compiler.
X	...
X	char	*(*func)();	/* local variable to hold pointer */
X	...
X	func = va_arg(ap, char *(*)());
XUnfortunately, va_arg turns the cast into something like:
X	(char *(*)() *) ...
Xinstead of the desired:
X	(char *(**)() ) ...
X...workaround?

try
	typedef char	*(*PFPC)();

	...

	func =	va_arg( ap, PFPC );


-- 

|| Tom Stockfisch, UCSD Chemistry	tps@chem.ucsd.edu

gwyn@brl-smoke.ARPA (Doug Gwyn ) (07/29/88)

In article <161@neti1.uucp> bdr@neti1.uucp (Brian Renaud) writes:
>Unfortunately, va_arg turns the cast into something like:

So, use a typedef.