Consider the following code:
int Test()
{
int a=10;
int c;
// Bug. User meant “=” but unfortunately wrote “==”
c==a;
return c;
}
This piece of code is obviously faulty. c is never assigned the value of a. c is actually never assigned any value.
When we compile this in VS 2008 we get the following warnings:
- warning C4553: '==' : operator has no effect; did you intend '=' ?
- warning C4700: uninitialized local variable 'c' used
In Xcode, we get no warnings at all. I just spent 30 minutes tracing this kind of bug in my code, in Xcode. I know I have made the mistake of replacing “=” with “==” several times in the past, but usually VS warns me in these occations. Xcode does not.
No comments:
Post a Comment