I was debugging some code yesterday and, after about fifteen minutes, found the culprit. This was in the code:
if (a = b)
{
// code
}
instead of this:
if (a == b)
{
// code
}
A very common mistake, but an aggravating one. My question is this. Does a compiler flag exist that checks for such potential errors (i.e. assignment operator where a comparison operator is normally expected, such as inside an if statement's parentheses) and issues a warning when that occurs? Or does one simply have to be vigilant when coding to avoid that error, and be on the lookout for that error when debugging, and you have to catch that error yourself?