We came across a very strange behavior with a code like this (this is a simplified version; it took quite a time before we were able to identify a similar problem in our code):
unsigned int x = 10; int a = ((int-1) * x; int b = ((int)-1) * x / 2; // [B]Result is not -5!!!!![/B] assert(a == -10); // OK assert(a == -5); //[B] Assert fails!!!!![/B]
Program was compiled with the Visual Studio 2008. Can anybody explain why 'b' is not -5? It seems like 'b' is treated as unsigned int instead of int.