Pointers to functions

D P Gilbert dpg at extro.ucc.su.OZ.AU
Fri May 17 14:18:18 AEST 1991


bhoughto at pima.intel.com (Blair P. Houghton) writes:

>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).

As I reach for the shift button to put yet another set of left and
right parentheses after a niladic function call I have begun to
wonder how to relieve such tedium. Wouldn't it be nice just to
write the function name without those parentheses (e.g. token.get
instead of token.get() ). The syntax of C tells me why but could it
be bent with a #pragma perhaps? Whenever I want the address of a
function I use "&" so I can understand my code 18 months later.

I know this amounts to heresy ... apologies in advance
Doug Gilbert



More information about the Comp.std.c mailing list