Andreas Schwab wrote:-

> Andrew Pinski <[EMAIL PROTECTED]> writes:
> 
> > sorry wrong number, I had meant 32769.
> >   if (foo (32769) != 1)
> >     abort ();
> 
> I think with 16 bit ints you should get 0 here, since (int)32769 ==
> -32767, which is less than 32767.

int foo(unsigned short x)
{
  unsigned short y;
  y = x > 32767 ? x - 32768 : 0;
  return y;
}

With 16-bit ints unsigned short promotes to unsigned int, since int
does not hold all the values.  Similarly 32768 has type unsigned int
and not int from inception.  So everything is unsigned and it should be:

  y = 32769U > 32767U ? 32769U - 32768U: 0;

which is 1 to my understanding.

Neil.

Reply via email to