To dereference or not dereference,

aglew at ccvaxa.UUCP aglew at ccvaxa.UUCP
Thu Mar 13 13:58:00 AEST 1986


>/* Written  4:55 pm  Mar  6, 1986 by kwh at bentley.UUCP in ccvaxa:net.lang.c */
>In article <44 at umcp-cs.UUCP> umcp-cs!chris (Chris Torek) writes:
>>		int f(), (*p)();
>>		p = f;
>>		p(1);
>>		(*p)(2);
>>		(**p)(3);
>>		(****************p)(4);
>
>Although there is no excuse for "p(1)", the other three examples are
>in fact correct.  Recall that there are only two things you can do
>with a function (not a pointer): call it (as in f()) or take its
>address (any other use of the name).  Thus "p = f" takes the address
>of function f and stores it in pointer p.

According to what I've heard about the ANSI C standard, "p(1)" is permitted,
with a half-decent reason behind it. C does not let you have segmented
names for functions. This way you can get them:

	       	struct {
			int (*draw)();
		} graph;

		graph.draw = my_favorite_draw_function;

		graph.draw();	/* is equivalent to */
		(*graph.draw)();

graph.draw is slightly cleaner, although more confusing.

Now, if we could just initialize a function pointer with the address of
an in-line lambda function.



More information about the Comp.lang.c mailing list