mtillman-921105 (8/3/2010)
However, I can accept your line of reasoning, but I still don't agree.
I can easily accept your line. I know, however, that it happens more often than not that we do have to agree with whatever implementation is, regardless whether it is consistent between different languages or not. If I try to use this in T-SQL:
declare @i smallint, @j-2 smallint;
select @i = 32767, @j-2 = 2;
print @i * @j-2;
I get "Arithmetic overflow error converting expression to data type smallint" error. When I try to use similar in C#:
short i = 32767;
i *= (short)2;
Console.WriteLine(i);
I get -2 printed in the Console window. I understand that neither of the above is what someone would perceive as reasonable, but I still accept both implementations. T-SQL does not allow overflows while C# simply wraps around (kinda like the sine) which is a great feature and it is used extensively in cryptography. So short 32767 + 2 is equal to -32767, and if I don't like it, I can force the T-SQL like behaviour by including the manipulation into checked {} block.
Oleg