indirect reference/use of procedures

Karl Heuer karl at haddock.ima.isc.com
Thu Mar 22 05:06:14 AEST 1990


In article <1205 at sdrc.UUCP> scjones at sdrc.UUCP (Larry Jones) writes:
>In article <A392C67xds13 at ficc.uu.net>, peter at ficc.uu.net (Peter da Silva) writes:
>>[an ANSI function-pointer can be invoked with pf() as well as (*pf)()]
>>What did the committee have in mind when they decided to make this syntax
>>part of the standard?
>
>Would you believe => printf("Hello, world\n"); ?
>
>Since "everyone knows" that you really use the address of a function to call
>it (not the function itself), and since function names usually turn into
>function pointers, it was far simpler to specify that function "objects"
>"always" turn into function pointers and that the function call operator
>requires a function pointer.

There are two ways to state the new rules: (a) Function lvalues decay into
pointer rvalues even when used in a function-call context; the function-call
operator expects a function-pointer operand (usually resulting from such a
decay).  (b) Function lvalues are insulated from such decay when used in a
function-call context; the function-call operator expects its operand to have
function type.  As a special case, a function-pointer used in such a function
context will automatically be dereferenced.

These two variants specify identical syntax and semantics, so they are equally
"correct", although (a) is the one actually used in the ANS.  (b) is the
pre-ANSI specification, except that the last sentence is a Common Extension
rather than a required rule.

My preference would have been to keep system (b), without the special case,
*and* to deprecate the existing rule that function lvalues automatically decay
into pointer rvalues.  Thus, the approved style would be
	pf = &f; /* not "pf = f;" */
	(*pf)();
which would improve the purity of the type system.

I think I did submit this one to X3J11.  They weren't too enthusiastic.  (This
was one of several things that *could* have been "fixed", but only in the long
run, by deprecating what is now a commonly used syntax; the Committee was much
more pessimistic about such things than I.)

Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint



More information about the Comp.lang.c mailing list