当前位置:网站首页>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.
边栏推荐
- Qt设置应用程序开机自启 解决设置失败原因
- 98. Embedded controller EC actual combat EC development board development completed
- 虚拟机的IP地址自动变为127.0.0.1
- R语言 数据的关系探索
- 测试的意义并不是能找到全部的缺陷
- 关于Request复用的那点破事儿。研究明白了,给你汇报一下。
- 织梦发布文章提示body has not allow words错误
- 1374. 生成每种字符都是奇数个的字符串 : 简单构造模拟题
- Digital twin Beijing the imperial palace, yuan universe is the process of tourism
- Imitation cattle forum project
猜你喜欢

Imitation cattle forum project

WeChat applet cloud development | personal blog applet

R语言 线性回归的有关方法

宝塔搭建PESCMS-Ticket开源客服工单系统源码实测

人工智能可信安全与评测

R语言 pca主成分分析的主要方法

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

响应式织梦模板美容整形类网站

Pytorch框架学习记录9——非线性激活
![漏洞分析丨HEVD-0x6.UninitializedStackVariable[win7x86]](/img/37/09ab9b5a490c6ab9bc7991ecc4c8f4.png)
漏洞分析丨HEVD-0x6.UninitializedStackVariable[win7x86]
随机推荐
Nacos 配置中心
iptables的使用简单测试
R语言 pca主成分分析的主要方法
Pytorch框架学习记录12——完整的模型训练套路
Simple test of the use of iptables
数据库内核面试中我不会的问题(1)
线程池处理异常的方法
仿牛客论坛项目
ahooks 是怎么处理 DOM 的?
C陷阱与缺陷 第7章 可移植性缺陷 7.9 大小写转换
【luogu P1912】诗人小G(二分栈)(决策单调性优化DP)
Telnet弱口令渗透测试
Kubernetes 如何实现组件高可用
C陷阱与缺陷 附录B Koenig和Moo夫妇访谈
R语言 线性回归的有关方法
latex paper artifact -- server deployment overleaf
Pytorch框架学习记录9——非线性激活
如何用Chrome编辑以及调试代码
Pytorch框架学习记录13——利用GPU训练
Convolutional Neural Network (CNN) mnist Digit Recognition - Tensorflow