Hi,
That's the normal behavior, see this scenario
short i = 32767 ; // the max positive value of a short aka int16
short j = 32;
the result of i + j overflow a short, so basically you have three choises:
1- ignore the overflow and do nothing, now you have an invalid result in k ,
tracking this error is a big pain!! ( I don;t really remember but I think
that this is what C/C++ does )
2- have the compiler do the check and throw an Overflow Exception, very
costly as now a lot of operations must be checked for this. C# provided a
controled way of doing this, see the checked keyword in C#
3- Automatically promote the type , this is the safer and faster way . I
think that Jave does this too ( is that right jon? )
Hope this help,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"rollasoc" <ho*****@hotmail.com> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
Hi,
Made me laugh so I though I'd share this.
short i = 32;
short j = 1;
short k = i + j;
gives an error
Cannot implicitly convert type 'int' to 'short'
That is a bit poo in my reckoning...
at least the following compiles.
short k = (short)(i + j);