You need a temporary to store the return value of foo
in order to not call it twice, then you can do this in a straightforward way with a couple ==
and an ||
. But if you really want the if
as something more "atomic" you can do this with a temporary value like this:
int temp;
if (temp = foo(), !((temp ^ N) * (temp ^ M))) {
// your code here
}
It might save a branch from the short-circuit evaluation, depending on what the compiler generates.
Without a temporary:
If you don't care about modifying N and M, you can do the test in a statement without a temp. N'
holds N ^ M
, M'
holds M ^ foo()
. So N' ^ M'
gives N ^ foo()
. The comma operator is evaluated left to right and the expression is has a value equal to its hand side.
if (N ^= M, M ^= foo(), !(M * (N ^ M))) {
// your code here
}