I never ever had problems with it in C. I actually had a problem with it in another language (might have been a BASIC) where = was contextual, so one could do "a = 10" and then somewhere down the line "if x = 5 then". I used == and couldn't figure out what was wrong for nearly 5 minutes (I think it was recognising (or not) as an unexpected token).
= and == should have different meanings.
I also like how JavaScript has ===, although it is a little superfluous.
Comments
"As far as it being a bug waiting to happen, C already has plenty of traps like that - '=' vs '==', '&' vs '&&', and so on."
And C programmers are already spending plenty of their time cursing the world because of those things. Let's not add more of that, shall we? ;)
I never ever had problems with it in C. I actually had a problem with it in another language (might have been a BASIC) where = was contextual, so one could do "a = 10" and then somewhere down the line "if x = 5 then". I used == and couldn't figure out what was wrong for nearly 5 minutes (I think it was recognising (or not) as an unexpected token).
= and == should have different meanings.
I also like how JavaScript has ===, although it is a little superfluous.
Interestingly PostgreSQL's pl/pgsql does that.
There are two operators, equality = and assignment :=
But where it is clear that assignment was meant, = is treated as assignment. this means you can:
Interestingly this is entirely a Postgres-ism. Oracle's PL/SQL offers no such "feature."