typedefs and prototypes

Karl Heuer karl at haddock.ima.isc.com
Wed Sep 21 11:14:16 AEST 1988


In article <8543 at smoke.ARPA> gwyn at smoke.ARPA (Doug Gwyn) writes:
>	void (*kb_widget1)(int key, void *data) { ... }

That can't be right.  If kb_widget1 is supposed to be a pointer to a function,
then its definition would take an initializer, not a function body.

>In <7135 at bloom-beacon.MIT.EDU> tada at athena.mit.edu (Michael Zehr) writes:
>>typedef void (*Keyboard_widget)(int key, void *data);

It looks like what you meant to say was:
	typedef void Keyboard_widget(int key, void *data);
which should clear up the error message.  No, you can't use the typedef when
you actually declare the function, since (as you noted) there's no place to
put the formal parameters.  (There's a note in the dpANS that explicitly
forbids inheriting the parameter list through a typedef.)

Note that the typedef is now "function".  To declare an object of type pointer
to function, you should use "Keyboard_widget *pf;".

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list