5 ms·
Do people really still make the `=` vs `==` mistake? GCC -Wall has had "warning: suggest parentheses around assignment used as truth value" since as long as I c
by rquirk 15y ago
Do people really still make the `=` vs `==` mistake? GCC -Wall has had "warning: suggest parentheses around assignment used as truth value" since as long as I can remember.
- alexchamberlain 15y agoYou make a good point, but the mistake is still made. Semantic correctness has other advantages, such as more optimisation when possible.
- jerf 15y agoThat's an easy and one might say picturesque example to give, but there are many variants, such as an if statement that in one branch turns out to change the value in that variable, then later on you forget about it and use it incorrectly. Or it gets passed into something taking it as a reference which unexpectedly modifies it, or so on and so forth. All of these are a lot harder to give examples of in a blog post because they don't really hit you in bite-sized chunks of example code. By definition, you're supposed to understand everything going on in an example chunk of code, so it's hard to show the problems that can emerge with hard-to-understand code.
- udp 15y agoIt's the one mistake that everyone seems to cite when complaining about C, and I've literally never seen it happen in all my years of programming. Right up there with fall-through cases.
- pnathan 15y agoI have made both mistakes.
- slowpoke 15y agoI use Yoda Conditions[1] in C-oid languages, so the error would be visible even without warnings (because the program would refuse to compile). [1]: http://stackoverflow.com/questions/2349378/new-programming-jargon-you-coined/2430307#2430307 http://stackoverflow.com/questions/2349378/new-programming-j...
- brendn 15y agoThat's fine when you make a comparison against a constant, but what if you're comparing two variables?