Take the 2-minute tour ×

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?

share|improve this question
Apparently, csh requires whitespace between arithmetic operators as well, according to Csh Programming Considered Harmful (faqs.org/faqs/unix-faq/shell/csh-whynot) –  bk1e Jun 20 '09 at 14:16
Just to add to the frivolity, in tcsh (to which /bin/csh is often a symlink), 4 - 3 + 1 evaluates to 2. –  Keith Thompson Mar 20 '13 at 23:14

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer


