当前位置:网站首页>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*/
边栏推荐
猜你喜欢
随机推荐
Day33 LeetCode
property语法
JSD-2204-Knife4j框架-处理响应结果-Day07
位运算简介
Graph adjacency matrix storage
Classification interface, Taobao classification details API
MySQL 中出现的字符编码错误 Incorrect string value: ‘\x\x\x\x‘ for column ‘x‘
pytest:开始使用
SkiaSharp 之 WPF 自绘 五环弹动球(案例版)
kubernetes各名词缩写
C陷阱与缺陷 附录B Koenig和Moo夫妇访谈
PX4模块设计之十五:PX4 Log设计
C陷阱与缺陷 第5章 库函数 5.5 库函数signal
左旋氧氟沙星/载纳米雄黄磁性/As2O3磁性Fe3O4/三氧化二砷白蛋白纳米球
牛血清白蛋白刺槐豆胶壳聚糖缓释纳米微球/多西紫杉醇的纳米微球DTX-DHA-BSA-NPs
【接口测试】JMeter调用JS文件实现RSA加密
Interview Blitz 70: What are sticky packs and half packs?How to deal with it?
技能大赛训练:A部分加固题目
案例:MySQL主从复制与读写分离
15 分钟带你入门 Grafana








