R
RoSsIaCrIiLoIA
if
{
unsigned u = -INT_MIN;
int i, sign = -1;
i = sign * u;
then i == INT_MIN or not?
{
unsigned u = -INT_MIN;
int i, sign = -1;
i = sign * u;
then i == INT_MIN or not?
The calculation is allowed to overflow, producing implementation-defined (IRoSsIaCrIiLoIA said:if
{
unsigned u = -INT_MIN;
int i, sign = -1;
i = sign * u;
then i == INT_MIN or not?
RoSsIaCrIiLoIA said:if
{
unsigned u = -INT_MIN;
int i, sign = -1;
i = sign * u;
then i == INT_MIN or not?
-INT_MIN is performed using signed int arithmetic (before the assignment), and it can
overflow (undefined behaviour).
Note that even if you do...
unsigned u = INT_MIN;
u = -u;
RoSsIaCrIiLoIA said:what do you say for
unsigned u = -(INT_MIN + 1);
u += 1;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.