Why are operators right associative in CShell that are left associative in C?

情到浓时终转凉″ 提交于 2020-01-05 08:36:14

问题


Following up from my previous question, why is CShell so different from C?

  • 4 - 3 + 1 = 2 in C.
  • 4 - 3 + 1 = 0 in CShell.

Any ideas?


回答1:


Generally the traditional notation is left to right (left associative) in human papers. So for humans (which used this notation long before c, csh or even any notion of computers):

4 - 3 + 1 = (4 - 3) + 1 = 1 + 1 = 2

Why? I guess that the best answer is because. It's the same as with driving left or right side of road. It really doesn't matter which side as long as everyone uses the same.

IMHO the csh is wrong as it is counter-intuitive. Possibly it was an error (they wanted left associative but coded wrongly) and become legacy as other things already depeneded on this.




回答2:


Different people wrote the products, and they had different views of how to handle the calculations. And since the C Shell was written second, I think they're at fault for not following the lead of the nominal parent language.



来源:https://stackoverflow.com/questions/1010119/why-are-operators-right-associative-in-cshell-that-are-left-associative-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!