Article View: net.lang.c
Article #9681Calling functions via pointers
From: Ed Nather
Date: Thu, 30 Oct 1986 18:40
Date: Thu, 30 Oct 1986 18:40
33 lines
1583 bytes
1583 bytes
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@astro.AS.UTEXAS.EDU
Technical Details
Message-ID:
<6165@ut-sally.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!natherShow 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!ut-sally!nather From: nather@ut-sally.UUCP (Ed Nather) Newsgroups: net.lang.c Subject: Calling functions via pointers Message-ID: <6165@ut-sally.UUCP> Date: Thu, 30-Oct-86 13:40:11 EST Article-I.D.: ut-sally.6165 Posted: Thu Oct 30 13:40:11 1986 Date-Received: Fri, 31-Oct-86 01:58:52 EST Organization: U. Texas CS Dept., Austin, Texas Lines: 33