🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9684

Re: Calling functions via pointers

#9684
From: Kenneth R. Ballou
Date: Fri, 31 Oct 1986 03:32
52 lines
2464 bytes
In article <6165@ut-sally.UUCP> nather@ut-sally.UUCP (Ed Nather) writes:
>A recent posting of the Boyer-Moore string search algorithm, written in C,
>contained several assignment statements in which a pointer to a function
>was assigned depending on circumstances.  The designated function was then
>called to do its thing.  The definition and call looked like this:
>
>   int (*action)();
>        .
>        .
>        .
>    if(action(arg1, arg2))
>        etc;
>
>and the pcc under 4.3bsd compiled everything without comment.  The C compiler
>written by Microsoft (v 3.0) was unhappy with the function call, however,
>insisting "action : not a function."

The Microsoft C compiler is of course correct.  'Action' is a pointer to
a function, and proper use would be to dereference the pointer as shown
immediately below.  It is regrettable that PCC (and hence PCC-based compilers)
allow this sloppy construct without at least issuing a warning.

>A quick look in K&R failed to reveal a call of the above format, but they
>suggested one which looks like this:
>
>   if((*action)(arg1, arg2))
>        etc;
>
>When I substituted the above form for the original, Microsoft C compiled the
>program without complaint and the code executed correctly; the pcc apparently
>will accept either format.
>
>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.

---
Kenneth R. Ballou		...!ucbvax!cartan!brahms!ballou
Dept. of Mathematics
University of California
Berkeley, California  94720
Newsgroups: net.lang.c
Subject: Re: Calling functions via pointers
Summary: 
Expires: 
References: <6165@ut-sally.UUCP>
Sender: 
Reply-To: ballou@brahms (Kenneth R. Ballou)
Followup-To: 
Distribution: 
Organization: Math Dept. UC Berkeley
Keywords: 
Technical Details
Message-ID: <153@cartanBerkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!nike!ucbcad!ucbvax!cartan!brahms!ballou
References: <6165@ut-sally.UUCP>

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!nike!ucbcad!ucbvax!cartan!brahms!ballou
From: ballou@brahms (Kenneth R. Ballou)
Newsgroups: net.lang.c
Subject: Re: Calling functions via pointers
Message-ID: <153@cartanBerkeley.EDU>
Date: Thu, 30-Oct-86 22:32:49 EST
Article-I.D.: cartanBe.153
Posted: Thu Oct 30 22:32:49 1986
Date-Received: Fri, 31-Oct-86 14:10:58 EST
References: <6165@ut-sally.UUCP>
Sender: daemon@cartanBerkeley.EDU
Reply-To: ballou@brahms (Kenneth R. Ballou)
Organization: Math Dept. UC Berkeley
Lines: 52