gcc
seems to be telling me int foo(int (*f)(void))
is the same as int foo(int (f)(void))
f
is a pointer to a function taking no argument returning int
. Why can we omit the *
here.
However, I also tried int (*p)(void)
and int (p)(void)
. The first p
is a function pointer, while the second is a function.
So, what's happening? Under what circumstances can the asterisk be omitted? I look it up in K&R and discovered nothing.
To quote from my copy of Harbison and Steele (5th edition, section 9.3):
In parameter lists, a type "function returning T" is implicitly rewritten to have type "pointer to function returning T".
That means that in the context of a formal parameter list, they are equivalent. In any other context, they are different.
As a matter of style, I would never omit the *.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.