Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uflorida!gatech!ulysses!ggs From: ggs@ulysses.homer.nj.att.com (Griff Smith) Newsgroups: comp.lang.c Subject: Re: typedefs and prototypes Summary: say what you mean and it works Message-ID: <10626@ulysses.homer.nj.att.com> Date: 21 Sep 88 23:52:30 GMT References: <7135@bloom-beacon.MIT.EDU> Organization: AT&T Bell Laboratories, Murray Hill Lines: 43 In article <7135@bloom-beacon.MIT.EDU>, tada@athena.mit.edu (Michael Zehr) writes: > > I'm writing a graphics interface library which ends up passing a lot > of pointers to functions. I've run into a problem with > typedefs and prototypes: > /* typedef and prototype declaration of a widget */ > > typedef void (*Keyboard_widget)(int key, void *data); > > Keyboard_widget kb_widget1; > > /* definition of a widget */ > > void kb_widget1(int c, void *data) > {...} > I get a "conflicts with previous declaration" at that point. If I try > to define the widget by the typedef, what syntax do i use??? /* Define the layout of a keyboard_widget function */ typedef void kb_widg_fn(int key, void *data); /* Define a type that is a pointer to a keyboard_widget function */ typedef kb_widg_fn* Keyboard_widget; /* I'm going to use kb_widget1, which is a keyboard_widget function */ kb_widg_fn kb_widget1; /* And here it is */ void kb_widget1(int c, void *data) {} /* This is accepted by C++, release 2.0; I can't speak for ANSI C */ -- Griff Smith AT&T (Bell Laboratories), Murray Hill Phone: 1-201-582-7736 UUCP: {allegra|ihnp4}!ulysses!ggs Internet: ggs@ulysses.att.com