Calling functions via pointers

Ed Nather nather at ut-sally.UUCP
Fri Oct 31 04:40:11 AEST 1986


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."
   
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?

-- 
Ed Nather
Astronomy Dept, U of Texas @ Austin
{allegra,ihnp4}!{noao,ut-sally}!utastro!nather
nather at astro.AS.UTEXAS.EDU



More information about the Comp.lang.c mailing list