Geoff Noel said:
hi, the following code generates warning C4244 :'+=':conversion from 'int'
to 'short' possible loss of data
void main()
int main()
{
short a=0, b=0;
a += b;
}
why?? thanks.
The assignment expression has type 'int', due to
standard conversion rules. All values of type 'int'
won't necessary be representable by type 'short int',
thus the warning.
Now my 'why' question: why not just use type 'int'?
Re your use of the word 'unexplained' in your message
subject:
I don't have VC7, but I have VC6, which
documents error C4244 thus:
============================================================
Compiler Warning (levels 3 and 4) C4244
'conversion' conversion from 'type1' to 'type2',
possible loss of data
An integral type was converted to a smaller integral type.
This is a level-4 warning if type2 is int and the size of
type1 is smaller than int. Otherwise it is a level-3 warning.
The conversion may have a problem due to implicit integral
conversions. For example:
short a, b, c;
a = b + c; // warning
============================================================
-Mike