Invoking pointers to functions (C sytle)
Jeff Edelen @ Colorado School of Mines
jedelen at slate.mines.colorado.edu
Mon Dec 3 07:42:12 AEST 1990
In article <6379 at harrier.ukc.ac.uk> dac at ukc.ac.uk (David Clear) writes:
>Take a look at this:
>
>main()
>{
> int fred(), (*p)();
>
> p = fred;
>
> (*p)(10); /* The right way */
> p(10); /* This works too */
>}
>
>int
>fred(x)
>...
>
>The (*p)(args) invocation is the K&R standard. p(args) also works on at
>least 4 different Unix compilers.
>
>Q: Is p(args) legal, portable C?
>Q: Is p(args) preferential to (*p)(args) as it looks neater, compare:
> s->p(args) (*s->p)(args)
>
>Any thoughts? I've only ever used (*p)()... I only came across p() recently.
>
>Dave.
It always seemed to me that p(args) is logically more consistent. If you
call the function fred() normally with fred(args) and fred (no parens)
is a pointer to the function, then if p is a pointer to the same function,
just adding the parens should have the same effect. As for what's legal...
anyone?
More information about the Comp.lang.c
mailing list