questionnaire

Keith Duddy keithd at anvil.oz
Tue Jan 23 14:15:17 AEST 1990


rick_jones at f616.n713.fido.oz (Rick Jones) writes:

> pA>4.  Do you consider passing a "pointer to a function" to another 
> pA>function
> pA>    which will (blindly?) use it to call that function, a "kosher"
> pA>    programming practice?

>I don't know about blindly, but yes I have quite a few programs that do that.
>particularly my format() module that does all the work for printf, fprintf,
>lprintf, etc.  is called with the pointer to an output function, allowing one
>function to perform multiple roles.

In fact this is the way in which one implements generics in C. If you are
storing some generic data type in a module then you must pass in a function
sometimes to do comparisons/retrievals etc. As long as the interface and
intention of the function is clearly defined then there is no problem. (look
at the qsort/bsearch standard libraries).
_______________________________________________________________________
                        __                     |    keithd at anvil.oz.au
 /_/  __  o _/ /_      /  )     __/ __/        |       (07)870 4999
/ \  (-' (  ( / /  o  /_ ' (_( (_/ (_/ (__/ o  |  Anvil Designs Pty Ltd   
    Don't be stupid Niel, everybody      /     |   PO Box 954, Toowong,
      knows potatoes can't fart.      (_/      |     4066, Australia.

[Disclaimer: Anvil Designs Pty Ltd actually encourage creative thought -
      but they don't want to be involved with creative litigation.]



More information about the Comp.lang.c mailing list