理解函数声明。 [英] Understanding a function declaration.

查看:69
本文介绍了理解函数声明。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我最近遇到了一个函数声明:

char(*(* x())[])();

这不是在某些代码中,而是在某些

组中的C问题帖子中。

我试图破译它返回的内容但是不能完全有意义

。有人可以解释这个功能应该是什么

一步一步地返回并扩展它。


谢谢,

Harsha

Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn''t make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.

Thanks,
Harsha

推荐答案

Sri Harsha Dandibhotla< ha ******** @ gmail.comwrites:
Sri Harsha Dandibhotla <ha********@gmail.comwrites:

>大家好。
我最近遇到了一个函数声明:
char(*(* x())[])();
这不是一些代码,但它是在某个
组中的C问题帖子中。
我试图破译它返回的内容但是不能完全理解
。有人可以解释一下这个功能是什么意思
返回并逐步扩展它。
>Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn''t make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.



你好Harsha,


您可能想找一个名为''cdecl''的有用工具,
可作为C源使用,因此可以在各种平台上运行。


对于您的示例,它给出了答案:


SHELL


Hello Harsha,

You may like to seek out a helpful tool named ''cdecl'',
which is available as C source and, thus, runs on a variety of platforms.

For your example it gives the answer:

SHELL


cdecl

输入'help''或'?''寻求帮助

cdecl解释char(* (* x())[])()

声明x作为函数返回指向函数的指针数组返回char

-

Chris。

cdecl
Type `help'' or `?'' for help
cdecl explain char(*(*x())[ ])()
declare x as function returning pointer to array of pointer to function returning char
--
Chris.


Sri Harsha Dandibhotla说:
Sri Harsha Dandibhotla said:

大家好。

我最近遇到了一个函数声明:

char(*(* x())[])();

这不在某些代码中但它是在某个

组的C问题帖子中。

我试图破译它返回的内容但是没有完全意义

出来了。有人可以解释这个功能应该是什么

返回并逐步扩展它。
Hello all.
I recently came across a function declaration as :
char(*(*x())[ ])();
This was not in some code but it was in a C questions thread on some
group.
I tried to decipher what it returns but couldn''t make complete sense
out of it. Can someone please explain what this function is supposed
to return and expand it step by step.



从标识符x开始。


立即查看。它是[?没有。


它是(?是:x(继续阅读,直到你到达右括号。


char(*(*) [])()

x()

" x是一个返回的函数"


现在读左边。是不是(?没有。


它是*,常量还是不稳定?如果是这样的话,请继续阅读,直到它不是:


char(*()[])()

* x()


" x是一个返回指针的函数


左边的下一个是a(?是的,这是一个分组的东西,所以我们

可以平衡括号,而不添加任何内容:


char(* [])()

(* x())


" x是一个返回的函数一个指向


的指针。看起来是正确的。右边的东西是一个[?是的,它是。


char(*)( )

(* x())[]


" x是一个函数,返回一个指向数组的指针

是钻井平台的事情一个(?没有。


左边的东西是a(?没有。


左边的东西是const,volatile还是* ?是的。继续阅读,直到

它不是。


char()()

*(* x ())[]


" x是一个函数,返回一个指针数组的指针


是什么东西到了留下了(?是的。请阅读)。


char()

(*(* x())[])


" x是一个函数,返回一个指向指针数组的指针


这是右边的东西[?没有。
是对不对的东西(?是的。请仔细阅读)...


char

(*(* x())[])()

" x是一个返回指向函数指针数组的指针的函数

返回"

左边的东西是一个(?没有。

是const / volatile / *吗?没有。

无论剩下什么,坚持下去结束:

char(*(* x())[])()

" x是一个返回指向函数指针数组的指针的函数

return char"


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

Start with x, the identifier.

Look immediately right. Is it a [ ? No.

Is it a (? Yes: x( Keep reading until you hit the closing parenthesis.

char(*(* )[ ])()
x()
"x is a function returning"

Now read left. Is it a ( ? No.

Is it a *, const, or volatile? If so, keep reading left till it isn''t:

char(*( )[ ])()
*x()

"x is a function returning a pointer to"

Is the next thing on the left a (? Yes, and this is a grouping thing, so we
can just balance out parentheses, without adding anything:

char(* [ ])()
(*x())

"x is a function returning a pointer to"

Look right. Is the thing on the right a [? Yes, it is.

char(* )()
(*x())[ ]

"x is a function returning a pointer to an array of"

Is the thing to the right a (? No.

Is the thing to the left a (? No.

Is the thing to the left a const, volatile, or *? Yes. Keep reading left until
it isn''t.

char( )()
*(*x())[ ]

"x is a function returning a pointer to an array of pointer to"

Is the thing to the left a (? Yes. Read up to the ).

char ()
(*(*x())[ ])

"x is a function returning a pointer to an array of pointer to"

Is the thing to the right a [ ? No.
Is the thing to the right a (? Yes. Read up to the matching )...

char
(*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning"

Is the thing to the left a (? No.
Is it const/volatile/*? No.
Whatever''s left, tack on the end:

char (*(*x())[ ])()
"x is a function returning a pointer to an array of pointer to function
returning char"

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于理解函数声明。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆