Are these pointer constructions equivalent?
Are these constructions equivalent?
int *(*p[10])() //array of ten pointers onto int functions
and
int *(*p())[1开发者_运维技巧0]
No.
Here's what the ever-wonderful cdecl says:
int *(*p[10])()
: declarep
as array 10 of pointer to function returning pointer toint
int *(*p())[10]
: declarep
as function returning pointer to array 10 of pointer toint
.
Intuitively, they "shouldn't" be the same since the declaration syntax of C++ is rarely that ambiguous (at least that's intuitive to me).
It might be worth pointing out that cdecl is also a command-line tool, it's just more convenient to link to the web page hosting an instance of it. Just wanted to make this clear, it's a (very) old tool, I first saw it mentioned in the "The C Programming Language" book by Kernighan and Ritchie, I believe I have the 2nd edition.
精彩评论