Hi Stephan,
I came across the following piece of code:
String a;
xub_StrLen n = 0;
n += a.Len();
This breaks on Windows (due to -werror). Because of the warning:
warning C4244: '+=' : conversion from 'int' to 'USHORT', possible loss
of data (in the last line of the fragment)
[...]
Does anybody have an idea what the problem is here?
By the holy standard, x += y where x, y are short works by promoting x,
y to int x', y', adding x' + y', converting int x' to short x'' and
assigning x'' back to x. MSC chose to warn about this (about the
potentially lossy "converting int x' to short x''" part).
Where is that in the standard? Is there a C-Standard, or is this in the
C++-Standard. I couldn't find it.
I still think this warning doesn't make sense. I am not interested what
the compiler does internally as long as the result is what I expect
(adding 60,000 + 60,000 is an overflow and that's what I expect when
adding shorts. If a possible overflow would cause a warning, almost any
arithmetic operation would have to warn for any type.)
I noticed that we didn't have this warning in an m172. Is there a new
warning that is responsible for this? Or is this a general warning for
possible-loss conversions (I thought we had already some before).
Rewriting this to
n = n + a.Len();
works. But it doesn't look much different.
Yes, MSC does not warn about that one, I guess it is a bug.
What? You mean "short = short + short" is also converted to "short =
(short)((int) + (int))" ?
If it would be a warning, I could never add two short values while
having -werror! I can't believe that!
Still confused,
-Bjoern
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]