varargs strangeness?

John C. Lusth jcl at bdrc.UUCP
Sat Dec 17 03:00:38 AEST 1988


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

It is at the assignment to f that the compiler complains

    "syntax error at or near symbol *"

On a SUN 4, the macro call va_arg(ap, void (*)()) expands to

    f =  (( void (*)() *)(ap += sizeof( void (*)())))[-1];

What's going wrong, how do I fix it, and why does the macro add
that extra star to the cast?

John C. Lusth
Becton Dickinson Research Center -  "designing the Ace Bandage of the future!"
bdrc!jcl at mcnc



More information about the Comp.lang.c mailing list