Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!thunder.mcrcim.mcgill.edu!mouse From: mouse@thunder.mcrcim.mcgill.edu (der Mouse) Newsgroups: comp.lang.c Subject: Re: More problems with passing functions as arguments. Message-ID: <1991Mar23.104656.13780@thunder.mcrcim.mcgill.edu> Date: 23 Mar 91 10:46:56 GMT Article-I.D.: thunder.1991Mar23.104656.13780 References: <27546@uflorida.cis.ufl.EDU> Organization: McGill Research Centre for Intelligent Machines Lines: 38 In article <27546@uflorida.cis.ufl.EDU>, pm0@reef.cis.ufl.edu (Patrick Martin) writes: [code compressed to save lines -dM] > void Function(i) > int i; > { printf("\nThe Number Is: %d\n",i); } > void Pass_Me_A_Function(F) > void (*F) (int); > { F(1); } > main() > { Pass_Me_A_Function(Function); } > This code works fine when compiled with gcc or my compiler at home. > When compiled with some of the older implementations of C it fails. > It fails on the declaration of F in Pass_Me_A_Function of > void (*F) (int); The "older" implementation probably does not understand prototypes. Remove the argument type declaration; try just void (*F)(); and see if it works an;y better. With some, you may find you also have to write the call as (*F)(1);. There are no compilers I am sure this is necessary for, but I have seen only a tiny fraction of all compilers in existence :-) In passing, why do you prototype the argument to Pass_Me_A_Function but not anything else? I would argue on stylistic grounds that Function should be prototyped to match the argument to Pass_Me_A_Function, though I think the given prototype is compatible with the given old-style declaration. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu