-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Support ^ operator with bools #7229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
if (some_long_predicate() != some_other_long_predicate()) {
// ...
} |
It's good to know that Actually, I believe using Some of the more useful ones:
|
Technically a duplicate of #5805 , which was marked as "closed".
For the intent in the OP, "check if two conditions are different", to me For keywords, note that currently Zig keywords influence control flow (short-circuit |
Hi, A small comment about : a != b != c != d vs a ^ b ^ c ^ d I might agree readable yes but "a != b != c != d" is more how mathematics would write it. Assumption : At time C was built it was mostly by people doing lot of math for software engineering, and Zig = C fixed so going forward with how we would write it in mathematics makes sens. Let me know what you think. Kinds regards |
AFAIK in mathematics this would imply |
Yes, you are right. |
No |
Uh oh!
There was an error while loading. Please reload this page.
For complex predicates where you want to check if two conditions are different, it's more straightforward to write:
than
especially if you only want to evaluate the predicates once.
If using this bitwise operator with bools is undesirable for some reason, a keyword operator
xor
similar toand
andor
could be added.(Current compiler behavior:
)
Note that this works trivially in C because
bool
is implicitly convertible toint
. To do the same conversion in zig we would have to write@boolToInt
around each predicate and compare the result of the xor to1
.The text was updated successfully, but these errors were encountered: