🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9692

Re: Calling functions via pointers

#9692
From: Guy Harris
Date: Fri, 31 Oct 1986 23:11
44 lines
2480 bytes
> >Is the original format documented anywhere?  Is it "standard" C or not?
> 
> It most certainly is *not* standard, and I would dare say it is sloppy form.

I don't like it either, but it *is* in the current ANSI C draft.  (Then
again, I don't like C's "array expression converts to pointer expression"
rules either.)  See section 3.3.2.2; it says "The expression that denotes
the function shall have type 'pointer to function'.", with a footnote
pointing out that "Most often, this is the result of converting an
identifier that is a function designator."  Thus, in the statement

	foo(x);

where "foo" was earlier declared as a function (or where it is implicitly
declared as a function by reference, but only Don't Be(e)s do this), the
name "foo" immediately gets converted to type "pointer to function", that
"pointer" gets "dereferenced" and the resulting function is called.  In the
example being complained about, in the statement

	if (action(arg1, arg2))
		etc;

the pointer "action" is dereferenced and the function is called.  If you say

	if ((*action)(arg1, arg2))
		etc;

"action" is dereferenced; this yields an object of type "function", but they
can't appear in expressions so it immediately gets converted back to type
"pointer to function"; that pointer value (identical to the value of
"action") is then dereferenced and the function is called.

It does make a perverse kind of sense, I suppose, if you think about it,
just as the similar handling of array types and array-valued expressions
does.  (If anyone wants to object that "C doesn't have array-valued
expressions", I refer them to section 3.2.2.1 in the latest ANSI C draft,
where they speak of "expressions that ha(ve) type 'array of <type>'.")

If you want the rationale for why this was done, check the Rationale
document that came with the latest ANSI C draft.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com (or guy@sun.arpa)
Technical Details
Message-ID: <8798@sun.uucp>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!pyramid!decwrl!sun!guy
References: <6165@ut-sally.UUCP> <153@cartanBerkeley.EDU>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!pyramid!decwrl!sun!guy
From: guy@sun.uucp (Guy Harris)
Newsgroups: net.lang.c
Subject: Re: Calling functions via pointers
Message-ID: <8798@sun.uucp>
Date: Fri, 31-Oct-86 18:11:47 EST
Article-I.D.: sun.8798
Posted: Fri Oct 31 18:11:47 1986
Date-Received: Mon, 3-Nov-86 20:11:25 EST
References: <6165@ut-sally.UUCP> <153@cartanBerkeley.EDU>
Organization: Sun Microsystems, Inc.
Lines: 44