Pointers to functions

Blair P. Houghton bhoughto at pima.intel.com
Thu May 16 09:37:37 AEST 1991


In article <1512 at caslon.cs.arizona.edu> dave at cs.arizona.edu (Dave Schaumann) writes:
>You have found one of the weirdnesses of ANSI-C.  When you have a pointer
>to a function, you (normally) invoke the function by saying
>	(*funptr)()
>However, ANSI, in it's infinite wisdom, decided that you should be able to
>say
>	funptr()
>in the same context, with similar results.

It's not weird at all.  It's rather consistent.  The actual
syntax is

	<expression>(<optional list of arguments>)

where the expression must evaluate to a function pointer.
A similar thing is true of arrays, structs, and unions, where
the syntaxes are

	<expression>[<expression>]
	<expression>.<member name>
	<expression>-><member name>

The only thing remotely weird about it is that now `funptr'
and `*funptr' are the same thing, but that's why function
poiners are often singled out for different semantic
treatment in the standard (many things you can do with
a pointer to int are forbidden with a function pointer).

				--Blair
				  "Many things you can do with
				   your own nose are forbidden
				   with your neighbor's."



More information about the Comp.std.c mailing list