Seeing a construction like this is a dead giveaway that the author is a C or C++ programmer. The double-equals signs represent a test for equality, as is expected. If just one equals sign was used, this would be an assignment operator to C programmers, which can be such a damaging mistake (the resulting statement meaning "a+b" (which will be 'true' for nonzero resulting values) and then "b equals c") that C programmers routinely use the double-equals form at all times, regardless of who they are talking to or whether the C form will be understood.

Hm, actually a + b = c won't even compile. + has higher precedence than =, so it resolves to ( a + b ) = c; literally, you're assigning the value of c to an expression, which isn't gonna work. That's not to say that you can't dereference an expression returning a pointer and assign to that expression, but that's a different thing: Dereferencing expressions return lvalues. Most expressions don't, including arithmetic expressions.

So, anyhow, MSVC says "error C2106: '=' : left operand must be l-value", and GCC says "invalid lvalue in assignment".

For breadth, by the way, it should probably be noted that Java, JavaScript, awk, and probably a few others also use == for comparison. By way of a similar convention, Pascal (which is not my favorite language) uses := for assignment and = for comparison.

Log in or registerto write something here or to contact authors.