prev up next   top/contents search

comp.lang.c FAQ list · Question 20.22

Q: If the assignment operator were :=, wouldn't it then be harder to accidentally write things like if(a = b) ?

A: Yes, but it would also be just a little bit more cumbersome to type all of the assignment statements which a typical program contains.

In any case, it's really too late to be worrying about this sort of thing now. The choices of = for assignment and == for comparison were made, rightly or wrongly, over two decades ago, and are not likely to be changed. (With respect to the question, many compilers and versions of lint will warn about if(a = b) and similar expressions; see also question 17.4.)

As a point of historical interest, the choices were made based on the observation that assignment is more frequent than comparison, and so deserves fewer keystrokes. In fact, using = for assignment in C and its predecessor B represented a change from B's own predecessor BCPL, which did use := as its assignment operator. (See also question 20.38).

prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North