当前位置:网站首页>C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.4 K&R C
C Expert Programming Chapter 1 C: Through the Fog of Time and Space 1.4 K&R C
2022-08-01 21:09:00 【weixin_Guest time】
/*When: 1978
*Who: Steve Johnson
*Event: Writing pcc, a portable C compiler
*Influence: Formed the basis of a generation of C compilers.
*/
/*The evolution of the C language is shown in Figure 1-2.
*1973-3 (early C)--->1976-9 (K&R C)--->1983-9 (ANSI C)(1)
*--->1967 (Simula 67)(2)
*1983 (Ada) (3)
*(1)(2)(3) together form 1985-9 (C++)
*/
/* Software Creed
*An unusual bug
The C language inherited a feature from Algol-68, the compound assignment operator, which allows a recurring operation to be written only once instead of twice, and gives the code generator a hint,That is, operand addressing can be so compact. The original way of writing the compound assignment operator is to write the assignment operator first, and then write the operator. There is a trick in the lexical analyzer of the B language that makes the implementation of =op more efficient than the op= form currently used.Simpler but confusing in this form, it's easy to add
b=-3; //subtract 3 from b
and
b= -3; //assign -3 to b
Confused.
Therefore, this feature has been modified to the form currently in use.As part of the modification, the code formatter program indent
was also modified to determine the obsolete form of the compound assignment operator, and to swap the two to convert it to the corresponding standard
form.This is a very bad decision.
No formatter should modify anything other than whitespace in the program.Unpleasantly, this approach introduces a bug where just about anything (as long as it's not a variable) swaps places with the assignment operator if it appears after the assignment operator.
*/
/* This bug may cause syntax errors, such as
*epsilon=.0001;
*will be replaced with
*epsilon.=0001;
*thisIf the statement fails to pass the compiler, you will immediately find the error
*value=!open; //value is set to the logical inverse of open
*will be silently exchanged to
*value!=open; //Compare unequal value with open
*This statement will compile without changing the value of value
*/
#include
int main() {
int b = 5;
b =- 3; /*从b中减去3*/
printf("b = %d\n",b);
b= -3; /*Assign -3 to b*/
printf("b = %d\n", b);
double epsilon=.0001;
printf("epsilon = %f\n", epsilon);
//can't pass the compiliation
//epsilon.=0001;
printf("epsilon = %f\n", epsilon);
int value = 3, open = 4;
bool result = value =! open; /*value is set to the logical inverse of open*/
printf("!open = %d\n", !open);
printf("result = %d\n", result);
result = value != open; /*value compares unequally with open*/
printf("result = %d\n", result);
return 0;
}
/* output:

*/ /*It seems that the previous problem does not exist now*/
边栏推荐
- 案例:MySQL主从复制与读写分离
- win10版本1803无法升级1903系统如何解决
- 那些关于DOM的常见Hook封装(二)
- LeetCode·每日一题·1374.生成每种字符都是奇数个的字符串·模拟
- Internet使用的网络协议是什么
- 15 分钟带你入门 Grafana
- 相亲模型与有限状态机
- C陷阱与缺陷 附录B Koenig和Moo夫妇访谈
- 和我一起写一个音乐播放器,听一首最伟大的作品
- ISC2022 HackingClub white hat summit countdown 1 day!Most comprehensive agenda formally announced!Yuan universe, wonderful!
猜你喜欢
随机推荐
idea实用快捷键合集——持续更新
[译] 容器和 Kubernetes 中的退出码完整指南
Pytorch学习记录(八):生成对抗网络GAN
kubernetes各名词缩写
wps excel 插入公式 整列
2022年秋招,软件测试开发最全面试攻略,吃透16个技术栈
R语言 pca主成分分析的主要方法
Record the first PR to an open source project
织梦通过数据库查询调用当前文章的留言
WeChat applet cloud development | personal blog applet
JS Improvement: Handwritten Publish Subscriber Model (Xiaobai)
98. Embedded controller EC actual combat EC development board development completed
漏洞分析丨HEVD-0x6.UninitializedStackVariable[win7x86]
如何用Chrome编辑以及调试代码
Goroutine Leaks - The Forgotten Sender
PyTorch笔记 - Attention Is All You Need (2)
R语言 线性回归的有关方法
string
图的邻接矩阵存储
Pytorch框架学习记录9——非线性激活








