excai

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2014年1月25日

摘要: 摘要: C语言程序可以看成由一系列外部对象构成,这些外部对象可能是变量或函数。而内部变量是指定义在函数内部的函数参数及变量。外部变量定义在函数之外,因此可以在许多函数中使用。由于C语言不允许在一个函数中定义其它 ...一、c程序存储空间布局C程序一直由下列部分组成: 正文段——CPU执行的机器指令部分;一个程序只有一个副本;只读,防止程序由于意外事故而修改自身指令; 初始化数据段(数据段)——在程序中所有赋了初值的全局变量,存放在这里。 非初始化数据段(bss段)——在程序中没有初始化的全局变量;内核将此段初始化为0。 栈——增长方向:自顶向下增长;自动变量以及每次函数调... 阅读全文
posted @ 2014-01-25 02:06 excai 阅读(363) 评论(0) 推荐(0)

2013年7月4日

摘要: The#includedirectivecausesacopyofaspecifiedfiletobeincludedintheplaceofthedirective.Thetwoformsofthe#includedirectiveare:#include#include"filename"Thedifferencebetweenthesetwoisthelocationthepreprocessorsearchesforthefiletobeincluded.Ifthefilenameisenclosedinquotes,thepreprocessorsearchesi 阅读全文
posted @ 2013-07-04 22:39 excai 阅读(202) 评论(0) 推荐(0)

2013年6月25日

摘要: Expert C Programming 中Reading the ANSI C Standard for Fun, Pleasure, and Profit 一节提到了pointer与const的关系,浓缩而言就是三个例子:char* p; const char* cp; cp=p; /*1 可行*/char* p; const char* cp; p=cp; /*2 不可行*/char** p; const char** cp; cp = p; /*3 不可行*/看完书之际,还是觉得有点云里雾里的感。3好理解,两个指针指向的对象完全不同(p指向指针which points to char, 阅读全文
posted @ 2013-06-25 02:30 excai 阅读(317) 评论(0) 推荐(0)

2013年6月22日

摘要: Repost from : http://www.ibm.com/developerworks/cn/linux/thread/posix_thread2/index.html互斥我吧!在前一篇文章中,谈到了会导致异常结果的线程代码。两个线程分别对同一个全局变量进行了二十次加一。变量的值最后应该是 40,但最终值却是 21。这是怎么回事呢?因为一个线程不停地“取消”了另一个线程执行的加一操作,所以产生这个问题。现在让我们来查看改正后的代码,它使用互斥对象(mutex)来解决该问题:thread3.c#include #include #include #include int myglobal 阅读全文
posted @ 2013-06-22 10:47 excai 阅读(215) 评论(0) 推荐(0)