简体   繁体   中英

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

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM