Is there any way in VS2010 C++ to have the IDE complain if I do something like
if (somevar = 2)
{
...
?
I try to pay attention to writing == instead of =, but not only using C++ but also VB and other languages, it just happens sometimes.
It takes really much time sometimes to find errors associated with my fault.
I think the possiblity that one really wants to write an if statement that also assigns a new value to a variable (as in my example above) is rather small. That is why I am hoping that VS2010 might have included an option that tells me about my possible flaw, but I haven't found one.
Is there any option like this?
Yes there is:
warning C4706: assignment within conditional expression
Just make sure you turn on all (not quite all on MSVS) warnings. (project properties -> C/C++ -> General -> Warning Level)
The alternative is using YODA conditions (2 == somevar), but that's ugly. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With