Pointers to functions

Erik Naggum enag at ifi.uio.no
Tue May 21 02:38:20 AEST 1991


D P Gilbert writes:
|
|   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.

Assuming

	struct ... {
		...
		void (*get)();
		...
	} token;

token.get() is a function call by virtue of the "()", while
token.get is the value of the function pointer.

Remember that statements such as

	3;

are legal in C, but sort of pointless.

	token.get;

is no exception.

Other languages don't know about function pointers and can alleviate
the user of the power thereof.

</Erik>
--
Erik Naggum             Professional Programmer            +47-2-836-863
Naggum Software             Electronic Text            <enag at ifi.uio.no>
0118 OSLO, NORWAY       Computer Communications      <erik at naggum.uu.no>



More information about the Comp.std.c mailing list