|What precedence for shift-left/shift-right operators? firstname.lastname@example.org (Timon Christl) (2002-06-28)|
|Re: What precedence for shift-left/shift-right operators? email@example.com (Thomas R. Truscott) (2002-07-02)|
|Re: What precedence for shift-left/shift-right operators? firstname.lastname@example.org (Timon Christl) (2002-07-04)|
|From:||"Thomas R. Truscott" <email@example.com>|
|Date:||2 Jul 2002 01:16:05 -0400|
|Organization:||SAS Institute Inc.|
|Posted-Date:||02 Jul 2002 01:16:03 EDT|
> ... this means that for example 1+2+3+4<<2 means
> "sum up 1, 2,3 and 4, then shift it left two times". I find the Pascal
> way more intuitive: ...
However the language does it, programmers will occasionally do it wrong.
The gcc compiler issues a helpful warning:
suggest parentheses around + or - inside shift
Another mistake I have seen is "if (x << y)" when the programmer
meant "if (x < y)". (Vanilla gcc does not warn about that.)
One can try to design the language to reduce mistakes.
To avoid the 1+2<<3 problem, require parentheses when mixing operators.
To avoid the if (x << y)" problem, require "boolean" values in the if.
I think language designers (and standards people) prefer this to warnings,
perhaps because they see warnings as vague and "non-normative".
But this is just converting warnings into mandatory errors.
I think mandatory warnings would also be appropriate.
Return to the
Search the comp.compilers archives again.