[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Operator precedence problem

Rustom Mody <rustompmody at> writes:
> Kernghan/Thomson/Ritchie (dont remember which) actually admitted to the
> fact that these precedences are wrong
> The mistake that C creators made was to treat bitwise operators as
> *logical* rather than as *arithmetic*

It was more that they did not take the opportunity to change them.  C
grew out of B, and B had only the one form of & and |.  These were
bitwise operators but, since they they were more often used for logical
combinations of tests, it made sense to give them low precedence.

When && and || were added to C, & and | should probably have been
"bumped up", but when you have a bunch of people who already know B (and
a bunch of B code you might be converting to C) it's easy to see why you
might not make that change.  After all, it's not like the language is
going to used for much more than this experimental Unix thingy!