operator + = on short int values - 奇怪的编译器警告 [英] operator += on short int values - strange compiler warning
问题描述
我有一些非常简单的代码片段:
short int n1,n2;
....
n1 + = n2;
我从VS2003收到警告 - VS2005:警告C4244:''+ ='':转换
来自''int'' 短,可能会丢失数据
n1 = n1 + n2;
这里我没有收到警告。奇怪......
我正在使用警告级别4.这是VC ++特定的吗?或者符合
标准?
Greets
-
Henryk
2006年2月7日06:12:57 -0800,Henryk <他************ @ gmx.de>写道:我有一些非常简单的代码片段:
short int n1,n2;
...
n1 + = n2;
我从VS2003收到警告 - VS2005:警告C4244:''+ ='':转换从''int''到''short'',可能会丢失数据>
n1 = n1 + n2;
这里我没有得到警告。奇怪......
我正在使用警告级别4.这是VC ++特定的吗?或者符合
标准?
在这两种情况下我都会预料到警告。根据类型推广规则,n1 + n2
的结果为int类型。
祝福,
Roland Pibinger
" Roland Pibinger" < RP ***** @ yahoo.com>在消息中写道
news:43 ************** @ news.utanet.at ...
< blockquote class =post_quotes> n1 + = n2;
我收到来自VS2003的警告 - VS2005:警告C4244:''+ ='':转换
来自''int'' 短,可能会丢失数据
n1 = n1 + n2;
这里我没有得到警告。奇怪......
我正在使用警告级别4.这是VC ++特定的吗?或者符合
标准?
我希望在这两种情况下都能发出警告。根据类型提升规则,n1 + n2的结果是int类型。
为什么?
Duane Hebert写道:" Roland Pibinger" < RP ***** @ yahoo.com>在消息中写道
新闻:43 ************** @ news.utanet.at ...
< blockquote class =post_quotes> n1 + = n2;
我从VS2003收到警告 - VS2005:警告C4244:''+ ='':转换
从''int''到''short'',可能丢失数据
n1 = n1 + n2;
<在这里,我没有得到警告。奇怪......
我正在使用警告级别4.这是VC ++特定的吗?或者符合
标准?
我希望在这两种情况下都能发出警告。根据类型提升规则,n1 + n2
的结果是int类型。
为什么?
$ b $我想我不明白这个问题。为什么?为什么两个操作数都会进行促销
?因为标准这样说(5/9)。或者
为什么在标准中如此?我不确定,请在comp.std.c ++中询问。
V
-
请删除资金从我的通过邮件回复时的地址
I have some very simple code fragment:
short int n1, n2;
....
n1 += n2;
I get an warning from VS2003 - VS2005: warning C4244: ''+='' : conversion
from ''int'' to ''short'', possible loss of data
n1 = n1 + n2;
Here I don''t get the warning. Strange...
I''m using warning level 4. Is this "VC++ specific" or conformant to the
standard?
Greets
--
Henryk
On 7 Feb 2006 06:12:57 -0800, "Henryk" <he************@gmx.de> wrote:I have some very simple code fragment:
short int n1, n2;
...
n1 += n2;
I get an warning from VS2003 - VS2005: warning C4244: ''+='' : conversion
from ''int'' to ''short'', possible loss of data
n1 = n1 + n2;
Here I don''t get the warning. Strange...
I''m using warning level 4. Is this "VC++ specific" or conformant to the
standard?
I would have expected the warning in both cases. The result of n1 + n2
is of type int according to the type promotion rules.
Best wishes,
Roland Pibinger
"Roland Pibinger" <rp*****@yahoo.com> wrote in message
news:43**************@news.utanet.at...
n1 += n2;
I get an warning from VS2003 - VS2005: warning C4244: ''+='' : conversion
from ''int'' to ''short'', possible loss of data
n1 = n1 + n2;
Here I don''t get the warning. Strange...
I''m using warning level 4. Is this "VC++ specific" or conformant to the
standard?
I would have expected the warning in both cases. The result of n1 + n2
is of type int according to the type promotion rules.
Why?
Duane Hebert wrote:"Roland Pibinger" <rp*****@yahoo.com> wrote in message
news:43**************@news.utanet.at...n1 += n2;
I get an warning from VS2003 - VS2005: warning C4244: ''+='' : conversion
from ''int'' to ''short'', possible loss of data
n1 = n1 + n2;
Here I don''t get the warning. Strange...
I''m using warning level 4. Is this "VC++ specific" or conformant to the
standard?
I would have expected the warning in both cases. The result of n1 + n2
is of type int according to the type promotion rules.
Why?
I guess I don''t understand the question. Why what? Why the promotions
are performed on both operands? Because the Standard says so (5/9). Or
why is it so in the Standard? I am not sure, ask in comp.std.c++.
V
--
Please remove capital As from my address when replying by mail
这篇关于operator + = on short int values - 奇怪的编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!