当前位置:网站首页>Suggestions and answer 8.1 C traps and defect chapter 8
Suggestions and answer 8.1 C traps and defect chapter 8
2022-08-01 21:03:00 【weixin_Guest time】
C language is a powerful and flexible tool.
How can we avoid these problems in C language?
The most important avoidance technique is knowing what you are doing.
Most of the mistakes are in the final opinion work the producer does before going to bed.So, before you prepare
to do something at the end, you'd better rest early.
Thinking about how to combine programs before actually combining them is crucial to getting a reliable result.
Advice:
Don't convince yourself of "The Emperor's New Clothes".
while (c == '\t' || c = ' ' || c == '\n')
c = getc(f);
This is illegal in C.
is equivalent to the following code:
while ((c == '\t' || c) = (' ' || c == '\n'))
c = getc(f);
(c == '\t' || c) cannot appear on the left side of an assignment operator.
while (c == '\t' || c == ' ' || c == '\n')
c = getc(f);
直接了当的表name intent.
Please use parentheses or other means to make your intent as clear as possible.
Sometimes we should also anticipate that those errors may appear, and prevent them in the way of writing the code.
while ('\t' == c || ' ' == c || '\n' == c)
c = getc(f);
考察最简单的特例.
Suitable for designing programs, conceiving how programs work, and testing how programs work.
使用不对称边界。
Watch out for bugs lurking in the dark.
Stick to only the well-known parts of the C language.
防御性编程
对程序用户和编译器事先的假设不要过多。
No matter how impossible it is, it can still happen at some point.To achieve a robust program, you should anticipate this exception.
In order for a C compiler to strictly detect various errors in a program, it must strictly detect the parts of the program that are intended to be portable, and at the same time leave out those parts of the program that are used to complete the specific machine-related parts..
Another reason, certain types of errors are inherently difficult to detect.
void set(int *p, int n) {
*p = n;
}
Context is required to say whether a program is legal or not.
//2.
//legal
int a[10];
set(a + 5, 37);
//illegal
int a[10];
set(a + 10, 37);
The ANSI C standard allows a program to obtain the address of the first position out of bounds at the end of an array.
边栏推荐
- Buttons with good user experience should not have hover state on mobile phones
- 这些 hook 更优雅的管理你的状态
- Qt设置应用程序开机自启 解决设置失败原因
- tiup mirror merge
- 【Dart】dart构造函数学习记录(含dart单例模式写法)
- 虚拟机的IP地址自动变为127.0.0.1
- Convolutional Neural Network (CNN) mnist Digit Recognition - Tensorflow
- Pytorch学习记录(八):生成对抗网络GAN
- Protocol Buffer 使用
- 列表页常见的 hook 封装
猜你喜欢

网络安全与基础设施安全局(CISA):两国将在网络安全方面扩大合作

STAHL触摸屏维修一体机显示屏ET-316-TX-TFT常见故障

Telnet弱口令渗透测试

98. Embedded controller EC actual combat EC development board development completed

New graduate students, great experience in reading English literature, worthy of your collection

What is the difference between a utility model patent and an invention patent?Understand in seconds!

测试的意义并不是能找到全部的缺陷

技能大赛训练:A部分加固题目

函数(二)

R语言 数据的关系探索
随机推荐
4.1 配置Mysql与注册登录模块
那些关于DOM的常见Hook封装(一)
win10版本1803无法升级1903系统如何解决
MySQL 中出现的字符编码错误 Incorrect string value: ‘\x\x\x\x‘ for column ‘x‘
Use WeChat official account to send information to designated WeChat users
JSD-2204-Knife4j框架-处理响应结果-Day07
R语言 数据的关系探索
关于Request复用的那点破事儿。研究明白了,给你汇报一下。
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
Which websites are commonly used for patent searches?
kubernetes各名词缩写
漏洞分析丨HEVD-0x6.UninitializedStackVariable[win7x86]
Postman 批量测试接口详细教程
system collection
Multithreaded producers and consumers
人工智能可信安全与评测
C陷阱与缺陷 第8章 建议与答案 8.2 答案
Pytorch框架学习记录8——最大池化的使用
Protocol Buffer 使用
15 分钟带你入门 Grafana