开发者

Are these pointer constructions equivalent?

开发者 https://www.devze.com 2023-02-20 17:48 出处:网络
Are these constructions equivalent? int *(*p[10])() //array of ten pointers onto int functions and int *(*p())[1开发者_运维技巧0]

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:

  1. int *(*p[10])(): declare p as array 10 of pointer to function returning pointer to int
  2. int *(*p())[10]: declare p as function returning pointer to array 10 of pointer to int.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消