Invoking pointers to functions (C sytle)

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Mon Dec 10 12:01:46 AEST 1990


In article <1990Dec08.214057.6280 at dirtydog.ima.isc.com> karl at ima.isc.com (Karl Heuer) writes:
> Function-call semantics in ANSI C may be described by either of two models
> (here f is a function and pf is a pointer-to-function):

What's common to your two models is that both involve kludges,
expressions decaying from one type into another, etc. Let me describe a
third model that would work perfectly well for C, doesn't require any
hacks in normal situations, and is quite intuitive.

(c) Functions and pointers are logically distinct types. Note that the
name of a function refers to type pointer-to-function, *not* function.
The interesting operations are
	(): pointer -> result-type
	&: function -> pointer, but this is generally redundant (you
	   almost never use functions directly in the first place)
	*: pointer -> function, but this is pointless (you only call
	   functions through pointers, so why use * unless you want to
	   see the actual instructions inside the function?)
As special (deprecated) kludges: Any function in a () context is
converted into the pointer. Any pointer-to-function in a & context is
left alone.

Surely you admit that this is just as clean as your model (b). It has
the advantage of being more realistic---at the machine level you call
functions by address, not by value. And it's a lot closer to common
practice before ANSI. So ANSI could have settled on the above model.

---Dan



More information about the Comp.lang.c mailing list