(Bert Douglas) wrote in message news:<. com>...
> When you have a pointer to a function, like this:
> int (*f)(void);
>
> I have always seen it invoked like this:
> result = (*f)();
>
> But now I see code that does simply this:
> result = f();
>
> The second style seems to be valid in Microsoft and Intel compilers.
> Even when you tell it to compile as standard C.
>
> I looked in the C language reference manual, and I don't see this
> syntax.
>
> Is this a new extension from C++, or C99 ? Or was it always like
> this?
it was always thus. Well from ANSI onwards (1989). I'm not sure about
K&R. some people think the (*f) form is clearer because it makes it
obvious you are calling thru a pointer.
In the ANSI standard it's section 3.3.3.2, but I don't find it an
obvious read. The Rationale is quite clear.
"Pointers to functions may be used either as (*pf)() or pf().
The latter construct, not sanctioned by the Base Document
[ie. K&R], [...] is unambiguous and invalidates no old code"
"all the following expressions are valid function calls
(&f)(); f(); (*f)(); (**f)(); (***f)();
pf(); (*pf)(); (**pf)(); (***pf)();"
ain't C fun?
--
Nick Keighley
"As I recall, OSI dealt with TCP/IP by just admitting it into the spec as a
variation of existing levels. This is akin to dealing with an Alien face
hugger by allowing it to implant its embryo in your body."