当前位置:网站首页>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*/
边栏推荐
- Interview Blitz 70: What are sticky packs and half packs?How to deal with it?
- C Expert Programming Preface
- Realize the superposition display analysis of DWG drawing with CAD in Cesium
- ORI-GB-NP半乳糖介导冬凌草甲素/姜黄素牛血清白蛋白纳米粒的研究制备方法
- 牛血清白蛋白-葡聚糖-叶黄素纳米颗粒/半乳糖白蛋白磁性阿霉素纳米粒的制备
- PX4模块设计之十五:PX4 Log设计
- 职场如象棋,测试/开发程序员如何突破成长瓶颈期?
- OSG Notes: Set DO_NOT_COMPUTE_NEAR_FAR to manually calculate far and near planes
- LeetCode·每日一题·1374.生成每种字符都是奇数个的字符串·模拟
- C陷阱与缺陷 第7章 可移植性缺陷 7.9 大小写转换
猜你喜欢
随机推荐
JSD - 2204 - Knife4j framework - processing - Day07 response results
P7215 [JOISC2020] 首都 题解
测试开发人均年薪30w+?软件测试工程师如何进阶拿到高薪?
记录第一次给开源项目提 PR
JS提升:如何中断Promise的链式调用
win10版本1803无法升级1903系统如何解决
C Pitfalls and Defects Chapter 7 Portability Defects 7.9 Case Conversion
C陷阱与缺陷 第7章 可移植性缺陷 7.10 首先释放,然后重新分配
软考 ----- UML设计与分析(上)
system collection
pytest:开始使用
函数(二)
使用员工管理软件,解锁人力生产力新水平,提高人力资源团队灵活性
牛血清白蛋白刺槐豆胶壳聚糖缓释纳米微球/多西紫杉醇的纳米微球DTX-DHA-BSA-NPs
An online JVM FullGC made it impossible to sleep all night and completely crashed~
Imitation cattle forum project
MySQL 中出现的字符编码错误 Incorrect string value: ‘\x\x\x\x‘ for column ‘x‘
Pytorch框架学习记录10——线性层
R语言 线性回归的有关方法
【接口测试】JMeter调用JS文件实现RSA加密