"msolem" <msolem@[EMAIL PROTECTED]
> wrote in message
news:1134687249.553014.197220@[EMAIL PROTECTED]
>I get this warning:
>
> C2705: Possible loss of data.
>
> when compiling this code:
>
> char var = 8;
> var = var / 2;
>
> If I change var from a char to a short, the warning disappears.
> I tried casting the '2' above to char, but that didn't help.
> Why am I gettng this warning when using a char?
>
> Mike
My $0.02 read:
While doing (var = var / 2;), the expression (var/2) is promoted to a
default short or an int (both 2 bytes, I think) because the constant 2 is
considered to be an int (or a short). A short or an int in the expression
-
the 2 - causes the promotion to the larger entity. Then the assignment to
a
char variable (var) demotes the short or int back into a char (one byte).
Whenever that occurs, the compiler probably automatically generates the
2705
warning. It's only a warning, so ignore it.
When you declared var as a short, the demotion to a char was not
performed.
Therefore, no 2705 demotion warning.


|