t*s 发帖数: 1504 | |
h*******s 发帖数: 8454 | 2 指向长度为2整形数组的指针吧。。。
【在 t*s 的大作中提到】 : 会场感谢
|
j*a 发帖数: 14423 | |
h*******s 发帖数: 8454 | 4 唉,看了这个问题就知道难怪c++没落。。。不过这个应该算c的吧。。。
【在 j*a 的大作中提到】 : 你这肯定是错的
|
d****n 发帖数: 1637 | 5 是啊,呵呵。
来试这个。
char (*(*x[3])())[5]
【在 j*a 的大作中提到】 : 你这肯定是错的
|
S**I 发帖数: 15689 | 6 this one is correct, all others are nonsense.
【在 h*******s 的大作中提到】 : 指向长度为2整形数组的指针吧。。。
|
t*s 发帖数: 1504 | 7 don't think so
【在 j*a 的大作中提到】 : 你这肯定是错的
|
t*s 发帖数: 1504 | 8 correct!
tested using gdb
thanks!
【在 h*******s 的大作中提到】 : 指向长度为2整形数组的指针吧。。。
|
j*a 发帖数: 14423 | 9 c真难哪
【在 t*s 的大作中提到】 : don't think so
|
h*******s 发帖数: 8454 | 10 这种题目最bt了。。。
x是一个函数指针数组,大小为3
指向的函数无参数,返回指向char[5]的指针。。。
【在 d****n 的大作中提到】 : 是啊,呵呵。 : 来试这个。 : char (*(*x[3])())[5]
|
|
|
t*s 发帖数: 1504 | 11 都是高手啊
我把b往其他长度数组指gcc还知道报警告
【在 t*s 的大作中提到】 : 会场感谢
|
d****n 发帖数: 1637 | 12 鼓掌!!
【在 h*******s 的大作中提到】 : 这种题目最bt了。。。 : x是一个函数指针数组,大小为3 : 指向的函数无参数,返回指向char[5]的指针。。。
|
r****t 发帖数: 10904 | 13 这个跟“最新某公司onsite面试题”比起来还算是简单的。
【在 h*******s 的大作中提到】 : 这种题目最bt了。。。 : x是一个函数指针数组,大小为3 : 指向的函数无参数,返回指向char[5]的指针。。。
|
h*******s 发帖数: 8454 | 14 要是能用电脑的话
好像有个软件还是网站叫c++decl还是cdecl专门把这种诡异的声明翻译成英语的
【在 r****t 的大作中提到】 : 这个跟“最新某公司onsite面试题”比起来还算是简单的。
|
t****t 发帖数: 6806 | 15 there was a tool called cdecl, that translate between english and C. now the
tool seems to disappear from default linux installation.
【在 h*******s 的大作中提到】 : 要是能用电脑的话 : 好像有个软件还是网站叫c++decl还是cdecl专门把这种诡异的声明翻译成英语的
|
h*******s 发帖数: 8454 | 16 放狗搜了一下,现在弄了个网站
http://cdecl.org/
不过我还真不知道这东西以前在linux发行版里面
the
【在 t****t 的大作中提到】 : there was a tool called cdecl, that translate between english and C. now the : tool seems to disappear from default linux installation.
|
t****t 发帖数: 6806 | 17 it is a good tool, i think it's from other unix variation, such as solaris.
maybe there is some license issue...
【在 h*******s 的大作中提到】 : 放狗搜了一下,现在弄了个网站 : http://cdecl.org/ : 不过我还真不知道这东西以前在linux发行版里面 : : the
|
r****t 发帖数: 10904 | 18 这个 thrust 在本版推荐介绍已经多年了。
【在 h*******s 的大作中提到】 : 要是能用电脑的话 : 好像有个软件还是网站叫c++decl还是cdecl专门把这种诡异的声明翻译成英语的
|
f******y 发帖数: 2971 | 19 谭浩强的书要熟读啊。
【在 t*s 的大作中提到】 : 会场感谢
|
h**i 发帖数: 712 | 20 你记住右左原则就不需要这东西。
【在 h*******s 的大作中提到】 : 放狗搜了一下,现在弄了个网站 : http://cdecl.org/ : 不过我还真不知道这东西以前在linux发行版里面 : : the
|
|
|
j*a 发帖数: 14423 | 21 有啥窍门?
【在 h**i 的大作中提到】 : 你记住右左原则就不需要这东西。
|
h*******s 发帖数: 8454 | 22 大概是按括号优先级,括号内从右向左念吧
【在 j*a 的大作中提到】 : 有啥窍门?
|
h**i 发帖数: 712 | 23 这么着名的东西居然没有普及
右左法则:首先从最里面的圆括号看起,然后往右看,再往左看。每当遇到圆括号时,
就应该掉转阅读方向。一旦解析完圆括号里面所有的东西,就跳出圆括号。重复这个过
程直到整个声明解析完毕。
The right-left rule: Start reading the declaration from the
innermost parentheses, go right, and then go left. When
you encounter parentheses, the direction should be reversed.
Once everything in the parentheses has been parsed, jump
out of it. Continue till the whole declaration has been
parsed.
【在 h*******s 的大作中提到】 : 大概是按括号优先级,括号内从右向左念吧
|
h*******s 发帖数: 8454 | 24 学习了,看过好几次,还是不太懂。。。
the
【在 h**i 的大作中提到】 : 这么着名的东西居然没有普及 : 右左法则:首先从最里面的圆括号看起,然后往右看,再往左看。每当遇到圆括号时, : 就应该掉转阅读方向。一旦解析完圆括号里面所有的东西,就跳出圆括号。重复这个过 : 程直到整个声明解析完毕。 : The right-left rule: Start reading the declaration from the : innermost parentheses, go right, and then go left. When : you encounter parentheses, the direction should be reversed. : Once everything in the parentheses has been parsed, jump : out of it. Continue till the whole declaration has been : parsed.
|
X****r 发帖数: 3557 | 25 Frankly I never get what is so hard about reading variable declarations.
As long as you can read C expressions, you can read variable declarations.
e.g. int (*b)[2] => (*b)[2] is a int.
So (*b) is an array of 2 ints, and b is a pointer to an array of 2 ints.
The same operator precedence applies here, too.
Another slightly more complex example
double (*(*f)(int (*)(int)))(double);
==> (*(*f)(int (*)(int)))(double) is a double
==> (*(*f)(int (*)(int))) is a function from a double to a double
==> (*f)(int (*)(int)) is a pointer to a function from double to a double
==> (*f) is a function from "int (*)(int)" to a pointer to a function from
double to a double,
whereas "int (*)(int)" is a pointer to a function from an int to an int
==> f is a pointer to a function from [a pointer to a function from a
double to a double] to [a pointer to a function from an int to an int].
【在 h*******s 的大作中提到】 : 大概是按括号优先级,括号内从右向左念吧
|
t****t 发帖数: 6806 | 26 not so hard for a clear brain. but frankly, i guess 80% of brains are not so
clear to decipher this mess, while 99% of brains are not as clear as yours.
..including my own.
【在 X****r 的大作中提到】 : Frankly I never get what is so hard about reading variable declarations. : As long as you can read C expressions, you can read variable declarations. : e.g. int (*b)[2] => (*b)[2] is a int. : So (*b) is an array of 2 ints, and b is a pointer to an array of 2 ints. : The same operator precedence applies here, too. : Another slightly more complex example : double (*(*f)(int (*)(int)))(double); : ==> (*(*f)(int (*)(int)))(double) is a double : ==> (*(*f)(int (*)(int))) is a function from a double to a double : ==> (*f)(int (*)(int)) is a pointer to a function from double to a double
|
h*******s 发帖数: 8454 | 27 老大们,在实际工作里遇到这种长声明的情况多么?
int].
【在 X****r 的大作中提到】 : Frankly I never get what is so hard about reading variable declarations. : As long as you can read C expressions, you can read variable declarations. : e.g. int (*b)[2] => (*b)[2] is a int. : So (*b) is an array of 2 ints, and b is a pointer to an array of 2 ints. : The same operator precedence applies here, too. : Another slightly more complex example : double (*(*f)(int (*)(int)))(double); : ==> (*(*f)(int (*)(int)))(double) is a double : ==> (*(*f)(int (*)(int))) is a function from a double to a double : ==> (*f)(int (*)(int)) is a pointer to a function from double to a double
|
t****t 发帖数: 6806 | 28 当然不多了, 你自己写程序这么写么?
以前常见的一个复杂玩艺是
void (*signal(int sig, void (*disp)(int)))(int);
但是现在一般都这样写:
typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);
【在 h*******s 的大作中提到】 : 老大们,在实际工作里遇到这种长声明的情况多么? : : int].
|
h*******s 发帖数: 8454 | 29 ~~~长出一口气
我查了一下typedef 在c89里面就是关键字了
为啥早年人们不用后一种写法呢,看起来清爽多了啊
【在 t****t 的大作中提到】 : 当然不多了, 你自己写程序这么写么? : 以前常见的一个复杂玩艺是 : void (*signal(int sig, void (*disp)(int)))(int); : 但是现在一般都这样写: : typedef void (*sighandler_t)(int); : sighandler_t signal(int signum, sighandler_t handler);
|