Chinaunix首页 | 论坛 | 博客
  • 博客访问: 60012
  • 博文数量: 15
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-04 13:29
文章分类
文章存档

2011年(1)

2008年(14)

我的朋友

分类: C/C++

2008-05-06 12:00:12

从去年10月份的时候闲来没事就在零零散散地看传说中的C Bible,即K&R的<>,个人感受是比谭浩强的那本<>要难懂,不过更贴近实际,主要是里面
的例子程序全都是以字符处理为主的,而且各个章节的联系很紧密,如果不连续去看,那些代码例子
更是难得看,不过里面关于概念的表述还是很经典的,现在摘抄当时作的笔记如下:
 
1、C Language is not specialized to any particular application .
 
2、理清变量的Storage Class 和 Linkage Class的区别:
   Linkage class是针对variable scope而言,而Storage class是针对内存分配和释放而 
   言!        
   Linkage Class: external,local  
   Storage Class: auto,static,malloc
  
   local variable的storage性质是auto; Each local variable comes into existence
   only when the function is called,and disappears when the function exits !
   But in static storage,local variable do retain their values between their
   calls. 所以说static variable是相对auto,malloc variable而言的。
 
   Scope rule : external 是相对local variable而言的。
   local variable只是作用于定义它的函数内部,而external的作用范围是:从申明external
   变量/函数开始到它所在的源文件的结束. K&R有如下表述:
   The scope of an external variable or a function lasts from the point at
   which it is declared to the end of the file being compiled .
 
   对于external variable的definition只能有一个,而declaration不限,可以落在不同的
   source file当中,可以将declaration放在header file当中,需要的时候#include即可。
 
   External variables are also useful because of their greater scope and
   lifetime.
   External variables, on the other hand, are permanent, so they can
   retain values from one function invocation to the next.
 
   A variable is external if it is defined outside of any function。不过
   如果我们给extern 外加一个static的storage的话,那么定义的变量的linkage就会变成
   internal !!! 这样做的好处是,在写大的程序的时候防止和其他源文件中的变量重名引发
   错误!
 
   static可以在函数内部,也可以在所有函数的外部,正如上面提到的,关于storage和linkage
   后续可以作更深入的研究哦
 
3、We must distinguish between definition and declaration ,
   Declaration refers to the place where the nature of the variable is stated
   but no storage is allocated !
   Definition refers to the place where the variable created or assigned
   storage !
 
4、character string = character array = array of characters
 
5、unary operators have higher precedence than the binary forms .
 
6、Operater precedence summary (only parts of the the whole rule)
   Arithmetic operator > relational operator > "==, !=" > && > ||
 
                                                                  未完待续~~~
  
   
阅读(1516) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~