Path: utzoo!utgpu!watmath!clyde!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: varargs strangeness? Message-ID: <8554@alice.UUCP> Date: 16 Dec 88 23:26:33 GMT References: <353@bdrc.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 51 In article <353@bdrc.UUCP>, jcl@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@europa.att.com