negate INT_MIN

J

jzhang918

Hi,

Should f(INT_MIN) return 0 according to the C99 for the following
function f (), or its result is undefined?

int f(int i)
{
i = i > 0 ? i : -i;
if (i<0)
return 0;
else
return 1;
}

Thanks!
Jie
 
G

Guest

Hi,

Should f(INT_MIN) return 0 according to the C99 for the following
function f (), or its result is undefined?

int f(int i)
{
i = i > 0 ? i : -i;
if (i<0)
return 0;
else
return 1;
}

It should return 1 when INT_MIN is equal to -INT_MAX. The behaviour
(not just the result) is undefined when INT_MIN is equal to -INT_MAX -
1.
 
¬

¬a\\/b

Hi,

Should f(INT_MIN) return 0 according to the C99 for the following
function f (), or its result is undefined?

int f(int i)
{
i = i > 0 ? i : -i;
if (i<0)
return 0;
else
return 1;
}

it seems undefined
if i see a char -128..127
-(-128)==?
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top