On Thu, 16 May 2013 07:34:18 +0200, Marco Leise <[email protected]> wrote:

Am Mon, 13 May 2013 10:00:40 +1000
schrieb Manu <[email protected]>:

void func(int x)
{
  x &= 0xFFFF;
  short s = x; // Error! (but we know x is 0 .. 65535)

  if(x < 256)
  {
    byte b = x; // Error! (we also know x is 0 .. 255)
  }
}
[snip]
Also what was your intention? func() practically takes a short
parameter. Maybe it's signature should be
    void func(short x) {...}
If that's a problem on the calling site, maybe that can be
fixed?

I believe the intention was to show an issue with the language, not to make a
function that assigns to a short and a byte only to throw them away.

Perhaps he needed to do some intermediate calculations at higher precision,
perhaps he needs it to be an int for interfacing with a C function, etc.

--
Simen

Reply via email to