Calling functions via pointers

Kenneth R. Ballou ballou at brahms
Fri Oct 31 13:32:49 AEST 1986


In article <6165 at ut-sally.UUCP> nather at 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 at ut-sally.UUCP>
Sender: 
Reply-To: ballou at brahms (Kenneth R. Ballou)
Followup-To: 
Distribution: 
Organization: Math Dept. UC Berkeley
Keywords: 



More information about the Comp.lang.c mailing list