In an unchecked context, is adding one to an integer with the value 2147483647 guaranteed to result in -2147483648?
For example, with the following code
const int first = int.MaxValue;
int second = first;
if ( second >= first )
{
Console.WriteLine( "First check" );
}
second++;
if ( second >= first )
{
Console.WriteLine( "Second check" );
}
In C++, it would be perfectly valid for both "First check" and "Second check" to be printed, as the optimizer can reuse the result of the first check for the second.
Is the same true of C#?
-2147483648