What's this =! operator?

That's two operators, = and !, not one. It might be an obfuscated way of writing

a = !b;
if (a) {
    // whatever
}

setting a to the logical inverse of b, and testing whether the result is true (or, equivalently, whether b was false).

Or it might be a mistyping of a != b.


Long ago, when dinosaurs roamed the earth and C ran on 5th edition UNIX on PDP-11s, =! was the 'not equals' operator. This usage was deprecated by the creation of Standard C, so now it means 'assign the logical inverse', as in a = !b. This is a good argument for always surrounding binary operators with spaces, just to make it clear to the humans reading the code what the compiler is thinking.

I'm a bit surprised nobody else mentioned this, but then again I may be the only SO user to have ever touched a C compiler that old.


a is assigned the boolean negation of b in that line. It is just a misformatted

if( a = !b ) {

... and an evil hidden assignment inside a condition.

Tags:

C++

C

Operators