惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
C
Cisco Blogs
Cloudbric
Cloudbric
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
S
Security Affairs
L
Lohrmann on Cybersecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
Simon Willison's Weblog
Simon Willison's Weblog
WordPress大学
WordPress大学
小众软件
小众软件
Security Latest
Security Latest
AWS News Blog
AWS News Blog
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
F
Full Disclosure
S
Schneier on Security
L
LangChain Blog
MyScale Blog
MyScale Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
Google Online Security Blog
Google Online Security Blog
Scott Helme
Scott Helme
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
A
Arctic Wolf
Martin Fowler
Martin Fowler
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
The Register - Security
The Register - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
Hacker News: Ask HN
Hacker News: Ask HN

Posts on Changkun's Blog

Why High-Output Systems Are Often the First to Stop Growing Dark Forest Theory: A Formal Derivation Agents (or Humans) in Goal-Directed and Goalless Environments: On Pipelines, Priors, and the Rhythm Between Exploration and Exploitation At the Boundary of Self-Reference: From Stable Structures in Artificial Intelligence to the Self as a Recursive Model in an Open Dissipative System 2023 Reading List 2022 Reading List 2021 Reading List Are PSS/USS and RSS Actually the Same Thing? Performance Differences from Page Faults vs. Prefetching 2020 Year-End Review Migration with Zero Downtime 2020 Reading List The All in Go Stack Pointers Might Not Be Ideal for Parameters Eliminating A Source of Measurement Errors in Benchmarks Setup Wordpress in 10 Minutes 我为什么不再写博客了? 2019 年终总结 2018-2019 读书清单 Ten years of blogging Rethinking the Reflections on Communications and Trusts 2018 年终总结 Go source code study is open source Go source study: unsafe Pattern Go source study: sync.Pool Go runtime programming A Million WebSocket and Go Designing Asynchronous RESTful APIs 分布式杂谈01:CAP 理论的误解 Issues of Human-Bot Interaction 压缩法与深度网络的泛化性 Go in 1 Hour UMSLT04: The Past and Present of SGD UMSLT03: A Gentle Start of Learning Theory UMSLT02: A Breif History of Neural Networks UMSLT01: A Breif History of Regularization 不笑不足以为道 论文笔记:Generalization in Deep Learning 2017 年终总结 2017 读书清单 深度学习的泛化理论简介 删除 GitHub 上已经提交的敏感信息 硕士生涯的第一年就这样告一段落了 人肉计算(10): 系统参与激励 人肉计算(9): 陷阱的解法 别聊,一聊你就暴露 人肉计算(8): 人肉计算与数据科学中的陷阱 人肉计算(7): 社会行为分析 Hexo + GitHub + Travis CI + VPS 自动部署 人肉计算(6): 预测市场 人肉计算(5): 信用风险评级模型 读书与回报 瞎扯: 对现代企业理论与当下IT企业的商业模式和信息产业链的规律性的思考 人肉计算(4): 输入数据聚合与PageRank 又一次打整了一下博客 人肉计算(3): 输入数据聚合与链路预测 人肉计算(2): 意图博弈 GWAPs 人肉计算(1): 众包与群众智慧 对后辈同学在计算机专业上的答疑与解惑 在德国的医疗及住院体验 这可能不是一个技术博客了 实验楼楼赛第3期-Python-题解 迅速更换了 DISQUS Electron 深度实践总结 良好的编码体验的三个方面 2016 年终总结 2016 读书清单 最近在着手写的文章 微信小程序文档极致总结 谈谈过去三个月在实验楼的实习经历 Built a Desktop Client for My Blog Guacamole 源码分析与 VNC 中 RFB 协议的坑 《高速上手 C++11/14》正式发布 Docker 极速入门教程02 - 镜像与容器管理 Docker 极速入门教程01 - 基本概念和操作 阶段性沉默 ELK+Redis 最佳实践 终于全面启用了 HTTPS 苹果开源了LZFSE无损压缩 Hash 碰撞的一种思路 记一次完整的 Kaldi-TIMIT 示例运行 Kaldi 上的 TIMIT 例子 Kaldi 安装与部署 从科研写作谈起 Swift API 设计指南 有趣的人类 所以其实论文并没有什么鬼用 Githug 通关记录及指南 小结一下这学期的收获 2015 读书清单 2015 年终总结 负能量爆表 转眼就快两个月了 博客迁移记录 大三总结 这个世界,终究不会是我们的。 Linux 内核分析 之六:Linux 内核创建进程的过程 小说「泽缘」 Linux 内核分析 之五:system_call中断处理过程的简要分析 大创项目的标题真是每年都在考验同学们的想象力啊
《C专家编程》读书笔记
Changkun Ou · 2013-11-06 · via Posts on Changkun's Blog

Published at发布于:   |   PV/UV: /   |   Reading阅读: 2 min

《C专家编程》是一本94年出版的讲语言的书,如今二十一世纪都已经过去十年多了,书上很多东西是不是依旧有用将是本文将要解答的问题。

尽量不要使用无符号数

当无符号数与有符号数再一起使用时,有符号数会被强转为无符号数。

1
2
3
4
int value_int = -1;
unsigned int value_uint = 5;
int result = (value_int < value_uint) ? 1 : 0;
printf("%d\n",result);// 结果为0

解释:C在计算含有不同类型表达式时,会将类型向上提升,上面代码中的int被提升为了unsigned int,使-1的补码被解析为很大的整数。

相邻的自字符串会被合并

1
2
char *str[] = {"hehe" "lala","woca"};
printf("%s",*str);// hehelala

优先级的问题

. 比 * 高:

1
2
*value.func -->
*(value.func)

[] 比 * 高:

1
2
int *array[] -->
int *(array[]) // array[]的元素为int*

函数() 比 * 高:

1
2
int *pfunc() -->
int* pfunc()// 返回值是int*

==和!= 比 位操作符 高:

1
2
value&mask!=0 -->
value & (mask != 0)

==和!= 比 赋值 高:

1
2
c = getchar() != EOF -->
c = (getchar() != EOF)

算数运算 比 位移运算 高:

1
2
value << 4 + constant -->
value << (4 + constant)

优先级最低:

1
2
i = 1,2 -->
(i = 1), 2

拆分声明、定义、typedef

  1. 找标识符
  2. 找被括号括起来的部分
  3. 找后缀操作符,如果是(),则表示是函数;如果是[],则表示是数组
  4. 找前缀操作符,如果是*,则表示指向某某的指针
  5. 找const和volatile,如果const,volatile紧跟类型,那么它作用于类型,其他情况下,作用于左边紧邻的项。
1
2
void (*signal(int value, void (*func)(int)))(int);
//signal是一个函数,接受一个int,一个函数指针,并返回一个函数指针。

左值和右值

左值通常表示存储结果的地址,在编译时可知右值表示地址的内容,值仅当运行时才被确定。

指针与数组名不等同的情况(定义为数组,却声明为指针,反之同)

假设定义:int array[10], *ptr; (1)使用数组名下表访问(array[1]),会直接将数组名的地址加上偏移值作为变量的地址。 (2)使用指针下表访问(ptr[1]),会先取指针指向的内容,然后将这个内容加上偏移值作为变量的地址。 原因:当定义为数组时,却声明为指针时,相当于用指针下表访问的方法来解析一个数组名下标,即先取数组第0号元素的内容,然后将这个东西加上偏移值作为变量的地址,从而访问了不该访问的东西。反之同。

数组与指针等同的情况

(1)编译器将表达式中的数组名当作指向该数组第0号元素的指针,下标当作指针的偏移量,array[i]被作为*(array+i); (2)编译器将函数参数声明中的数组名当作指向该数组第0号元素的指针,即在函数内部得到的是指针,而不是数组名。 根据(1),可知道下面这条为谣言: 用指针迭代数组比用下标迭代数组更快 根据(2),可以解释为什么在传递数组后,不能使用下方法计算数组长度:

1
2
3
4
int arr_lenth(int arr[])
{
    return sizeof(arr)/sizeof(arr[0]);// 返回值必为1,因为arr为指针,不是数组名
}

值得注意的是(2)中将数组改写为指针不是递归定义: 实参char hello[10][10]被改写为char (*hello)[10],这里将数组的数组改写为数组的指针 实参char *hello[10]被改写为char **hello,这里将指针数组改写为指针的指针 实参char (*hello)[10]不被改变,因为这时hello是指针非数组

interposition

interposition指的是用户定义的函数取代库中声明完全相同的函数,注意这不是指重载,而是指:

1
2
char* strchr(const char *s, int c);//user defined
char* strchr(const char *s, int c);//library

出现interposition时,需要注意:

1
2
3
4
5
6
7
char* strchr(const char *s, int c);//user defined
int main()
{
     strchr(...);//调用的是user defined的函数
     strstr(...);//这个函数会调用库函数strchr,此时由于interposition,变成调用用户定义的strchr
     return 0;
}

注意:出现interposition时,vs2012会警告:inconsistent dll linkage

堆栈段作用

(1)存储局部变量 (2)函数调用时,存储有关的维护信息 (3)用作暂时存储区: 计算一个很长的表达式时,会把部分结果先压到堆栈中。