Path: utzoo!attcan!uunet!samsung!usc!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: How do I prototype this? Message-ID: <16995@haddock.ima.isc.com> Date: 30 Jun 90 19:14:59 GMT References: <326@demott.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 34 In article <326@demott.COM> kdq@demott.COM (Kevin D. Quitt) writes: >I'm invoking functions through an array of struct. My compiler generates >a warning in the following two cases. How do I declare prototypes given: > (*configuration[ tnum ].fn)( cfg, token ); Change the struct definition: struct token_def { ... i16 (*fn)(cfg_t, token_t); } where cfg_t and token_t are the types of the arguments. > struct parse_info { CMD_IN *pici; ... } > (*(pi[0].pici->func))(); Similarly, use a prototype for the `func' member of the struct you've typedef'd to `CMD_IN'. > Note also that depending upon the circumstances, the call will have >zero, one or two parameters. Oh, that makes it a bit trickier. I presume the individual functions are not variadic (since you want to be able to pass zero args), and you just want to be able to store them all in the same structure type. Okay, then, the proper way to do it is to cast the constants to a common type in the initializer, and cast them back to the correct type before using them: struct token_def { ... void (*fn)(void); }; struct token_def configuration[] = { { TITLES, 0, "TITLES", (void (*)(void))paint_titles }, }; (*(i16 (*)(cfg_t, token_t))configuration[ tnum ].fn)( cfg, token ); Any function-pointer type may be used for the generic pointer; I used the simplest, `void (*)(void)'. You may want to use a typedef for this and the other function-pointer types. Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint