我爱南瓜
I love my little pumpkin
IT博客
首页
新随笔
联系
聚合
管理
随笔-8 评论-5 文章-0 trackbacks-0
Complicated Declarations
对识别C/C++中复杂的声明,Thinking in C++中介绍了一种简单的方法,right-left-right,即以变量为中心,向右走,一直到碰到右括号或不能再往右走,再往左走步,碰到左括号,再向右走。。。
如对于void * fun(void),可以翻译为fun is a function that requires no argument and returns pointer to void。而void (* fun)(int),则可以理解为fun is a pointer to function that requires int argument and returns void。
值得注意的是,对于像function这样的情况,必须先说argument,再说return value,两者都不可缺。例如,
void
*
(
*
set_handler(
void
(
*
f)))();
理解为,set_handler is a function that requires ... argument and returns pointer to function that requires no argument and returns pointer to void。
碰到具体的符号的读法如下:
id
'
id
'
is
a
*
pointer to
(
---
) funciont that requires
---
argument(s) and returns
[
---
] array of
type type
Thinking in C++中也提到,这种方法对大部分声明有效,里面没有提到无效的声明(我也想不到),可能是其他一些比较变态的声明。而The C programming language则从C的语法角度解释了复杂表达式的解读方法。
dcl: optional
*
'
s direct-dcl
direct
-
dcl: name
(dcl)
direct
-
dcl()
direct
-
dcl[optional size]
用top down的方法,即可很容易的出上面的结论了。具体请看相关章节The C Programming Language 5.12
posted on 2005-08-03 00:07
pumpkin
阅读(262)
评论(0)
编辑
收藏
引用
只有注册用户
登录
后才能发表评论。
不当之处,欢迎纠正。
<
2005年8月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
2005年8月 (8)
搜索
最新评论
1. re: zoj-2234-Binary Search Heap Construction
谢谢了,很有启发
--谢谢
2. re: zoj-1167-Trees on the Level
Thanks a lot !!!
--D.B.
3. re: zoj-2234-Binary Search Heap Construction
哈哈,谢谢!多亏了你呀,不然肯定超时死了!
--ybfqing
4. 谢谢你的资料,,,
~~~~
--sophia_philem
5. 谢谢你的资料,,,
~~~~
--sophia_philem
阅读排行榜
1. zoj-2234-Binary Search Heap Construction(1739)
2. zoj-1010-Area(880)
3. zoj-1167-Trees on the Level(862)
4. zoj-1990-Subway Tree Systems(799)
5. UML学习笔记(1)(732)
评论排行榜
1. zoj-2234-Binary Search Heap Construction(4)
2. zoj-1167-Trees on the Level(1)
3. zoj-1990-Subway Tree Systems(0)
4. zoj-1319-Black box(0)
5. UML学习笔记(1)(0)