免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 2094 | 回复: 11
打印 上一主题 下一主题

改变氛围,从我做起 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-14 18:28 |只看该作者 |倒序浏览
开发C/C++程序转眼已经5年了,5年来看了不少书,写了不少程序,感觉应该学会不少东西;
可还是不断的惊艳于开源大师们的作品,不禁问自己这几年到底学到了什么?

前几天看到了一家外企的一道笔试题目,深有感触,题目是:
static 关键字分别用在局部变量、全局变量、类成员前面有什么不同含义?

这好像是经常能看到的问题,对于C/C++开发人员来说应该是很基本、很容易的一个问题,可是我相信能写出标准答案的人不多...

为什么?

为什么中国大陆这么多软件开发人员却很少有大师级的人物?甚至远远不如台湾?

造成这种情况的罪魁祸首是国内整个软件行业的浮躁和急功近利氛围。

可是我们不能永远都惊艳于大师的作品!
所以我们需要改变氛围,脚踏实地!

口号喊完了,呵呵
今天起重新看c language programming,会向大家请教一些问题,请不吝指导。

No1:
书中有一句话没明白:the standard library ensures that an input text stream appears as a
sequence of lines, each terminated by a newline.

不知道这句话怎么解释,标准I/O库可以保证吗?

论坛徽章:
0
2 [报告]
发表于 2006-03-14 20:22 |只看该作者
支持楼主的这种精神.

论坛徽章:
0
3 [报告]
发表于 2006-03-14 21:04 |只看该作者

是不符合论坛问题标准吗?

不太明白这句话的含义:
the standard library ensures that an input text stream appears as a
sequence of lines, each terminated by a newline.
标准库能否确保,怎么确保文本流是一些以新行符结尾的行序列?
谢谢!

论坛徽章:
0
4 [报告]
发表于 2006-03-15 08:14 |只看该作者
我觉得这句话的意思是这样的,C标准库认为输入的字符流(比如文本文件啊)是一行一行,一行结束就新行开始。。。
比如我们通常用fgets(C)或getline(C++)来处理文本,大概就是这个意思吧

论坛徽章:
0
5 [报告]
发表于 2006-03-15 09:08 |只看该作者
基础还是很重要的

论坛徽章:
0
6 [报告]
发表于 2006-03-15 09:30 |只看该作者
static global variables can only be accessed by the functions defined in the same file.
usually this usage is to encapsulate infomation in .c or .cc files; they can not be
exported by the "extern" storage specifier to the .h files


static local variables can only be accessed by the function in which they are defined.
this usage is also for encapsulation, however, in this case, on the function level.


static class members are declared in the .h files. except for the members of const int type,

which can be initialized in the class declaration, all members of other types should be
initialize outside the class declaration, usually in .cc or .cpp files. Note ,however, it
can not be initialized in the class constructor's initialization list.

水平的提高,除了数量,还得看质量,到了一定层次,甚至质量会占上风。对看些经典书籍吧!

努力提高自我。希望有朝一日,我们的祖国能强盛到这样的地步:台湾主动要求回归,而不是
现在这种尴尬局面。

论坛徽章:
0
7 [报告]
发表于 2006-03-15 09:39 |只看该作者
更正一下:
static class members are declared in the class declaration, which is often in .h files.
(by the way, it is also proper to declare a class in .cc files, depending on the
encapsulaion requirement)

论坛徽章:
0
8 [报告]
发表于 2006-03-15 11:01 |只看该作者

非常感谢

非常感谢大家!

论坛徽章:
0
9 [报告]
发表于 2006-03-15 22:20 |只看该作者
原帖由 aldebran 于 2006-3-15 09:30 发表

static local variables can only be accessed by the function in which they are defined.
this usage is also for encapsulation, however, in this case, on the function level.

局部变量前面加static并不是不能被别的函数访问吧,不加static也不能被其它函数访问。
相反加了static就相当于全局变量了(不过还是不能被其它函数访问),每次访问值都不变。

论坛徽章:
0
10 [报告]
发表于 2006-03-15 23:15 |只看该作者
局部变量用 static 修饰就把这个变量分配在静态存储区,而不是跟随每次函数被调用时在栈上分配。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP