varargs strangeness?

Andrew Koenig ark at alice.UUCP
Sat Dec 17 09:26:33 AEST 1988


In article <353 at bdrc.UUCP>, jcl at bdrc.UUCP (John C. Lusth) writes:
> I have a variadic function to which I pass a pointer to a function returning
> void.  Distilled, my function looks like
> 
> error (va_alist)
> 
> va_dcl
> 
> {
>     va_list	ap;
>     void	(*f)();
> 
>     va_start(ap);
> 
>     f = va_arg(ap, void (*)());
>     .
>     .
>     .
> }

The C preprocessor is pretty simple-minded.  This makes it
hard (probably impossible) for varargs to cope with argument
types that cannot be transformed into their related pointer
types by appending a *.

void(*)() is definitely not such a type.

To make it into one, use a typedef:

error (va_alist)

va_dcl

{
    va_list	ap;
    typedef 	void (*voidfuncp)();
    voidfuncp	f;

    va_start(ap);

    f = va_arg(ap, voidfuncp);
    .
    .
    .
}

``C Traps and Pitfalls'' describes varargs.h in some detail
starting on page 134.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list