More problems with passing functions as arguments.

der Mouse mouse at thunder.mcrcim.mcgill.edu
Sat Mar 23 20:46:56 AEST 1991


In article <27546 at uflorida.cis.ufl.EDU>, pm0 at 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 at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list