On 11/21/2026 6:58 PM, Dan Cross wrote:
> In article <6b02…@news.sunsite.dk>, > Arne Vajhøj <ar…@vajhoej.dk> wrote:
>> On 11/20/2026 3:24 PM, Arne Vajhøj wrote:
>>> On 11/20/2026 3:10 PM, Simon Clubley wrote:
>>>> [snip]
>>> Doesn't C require/mandate short circuiting in cases like this??
>> >> I believe the VMS landscape looks like: >> >> Undefined(*) L to R L to R >> all short circuit >> [snip] >> VMS Fortran .and. >> .or. >> VMS Pascal and and_then >> or or_else >> C & && >> | || >> Ada and and then >> or or else >> Java & && >> | || >> Python & and >> | or >> PHP & && >> | || >> and(**) >> or(**) >> [snip]
> > For C, Java, Python, and (probably?) PHP, you are mixing up > different categories of operators: `&` and `|` are bitwise > operators in those languages, while `&&` and `||` are boolean > operators. Since they are intended to do differnt things, the > semantics are different.
Those 4 are a bit different. Java has both bitwise & and | on integer types and logical & and | on booleans. In C and Python bool are sort of an int so bitwise and logical are the same. PHP just auto converts booleans to ints for bitwise operator. But all 4 quacks like a duck.
> I doubt that there are many many languages that would introduce > short-circuiting behavior for bitwise operators. But note also > that we may see behaviors like this: > > ```c > #include <stdio.h> > int > main(void) > { > int a = 1, b = 2; > > if (a) > printf("a is true\n"); > if (b) > printf("b is true\n"); > if (a & b) > printf("both are true\n"); > else > printf("but `&` is not a boolean operator\n"); > > return 0; > } > ```
Good point. The problem here is the use of int instead of bool. #include <stdio.h> #include <stdbool.h> int main() { bool a = 1, b = 2; if (a) printf("a is true\n"); if (b) printf("b is true\n"); if (a & b) printf("both are true\n"); else printf("but `&` is not a boolean operator\n"); return 0; } Outputs a different result. But treating int's as booleans is an integrated part of C. And it has spilled over to many other languages. So yes - if working with int's instead of bool's, then bitwise operators can not be used as logical operators. Arne