I accidentally typed =! instead of != that caused a huge bug in a system that went undetected for a while; I have fixed it since but I’m curious as to what =! does.
I had something like this
void foo(int param)
{
int a = 0;
...
if (a =! param)
{
// never got here even when `a` was not equal to `param`
}
...
}
Can someone explain what the above if statement is evaluating ?
This expression:
assigns the value
!paramtoa.!paramis negated version of param evaluated in boolean context.Assignment operators return the value of the right hand side, so,
if (a = !param)also executes theifbody, if!paramis true.