int a = -2147483648; [英] int a = -2147483648;

查看:125
本文介绍了int a = -2147483648;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



警告C4146:一元减号运算符应用于无符号类型,结果仍然是

未签名。




解决方案



" Skybuck Flying" < sp ** @ hotmail.comwrote in message

news:f6 ********** @ news6.zwoll1.ov.home.nl ...
< blockquote class =post_quotes>
>

警告C4146:一元减号运算符应用于无符号类型,结果仍然是

unsigned。





有符号整数的值太大(检查整数边界)


Skybuck飞行说:


>

警告C4146:一元减号运算符应用于无符号类型,结果

仍然没有签名。





警告CLC123:长期的巨魔返回到comp.lang.c - 在撰写回复之前建议

归档检查。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日


On Sun,2007年7月8日08:03:23 +0200,Skybuck Flying写道:


>

警告C4146:一元减号运算符应用于无符号类型,结果仍然是

无符号。





我猜你有32位整数和2'补码。

C99基本原理(6.4.4.4。)说 ;尽管一般规则

,文字常数是非负的,3 ......脚注

是3注意-4是表达式:一元减去操作数4.

INT_MAX是0x7FFFFFFF,所以十进制常数为0x80000000不是
适合签名的int,如果INT_MAX == LONG_MAX,甚至不是

签名长。在C89中,这将导致它具有无符号类型。

否定它会产生UINT_MAX + 1 - 0x80000000,即0x80000000,

不适合签名的int。

尝试使用:

long a = -2147483647 - 1,例如MSVC #define''s INT_MIN this

way(但带括号)周围)。请注意,在C89中没有类型是

*必需*才能保持该值,因此程序不会随处可移动。但是使用long会使它即使在具有16位int的系统上也可以移植,只要它们使用两个补码。

(如果你的意思是INT_MIN。如果你的意思是。你有C99也许你想要

使用INT32_MIN并声明一个为int32_t,这些是在

< stdint.h>中定义的。)


-

Army1987(将NOSPAM替换为电子邮件)

永远不要归咎于可以充分解释的恶意

愚蠢。 - R. J. Hanlon(?)



warning C4146: unary minus operator applied to unsigned type, result still
unsigned.

?

解决方案


"Skybuck Flying" <sp**@hotmail.comwrote in message
news:f6**********@news6.zwoll1.ov.home.nl...

>
warning C4146: unary minus operator applied to unsigned type, result still
unsigned.

?

too large value for signed integer (check integer boundary)


Skybuck Flying said:

>
warning C4146: unary minus operator applied to unsigned type, result
still unsigned.

?

warning CLC123: longstanding troll returns to comp.lang.c - suggest
archive check before composing reply.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


On Sun, 08 Jul 2007 08:03:23 +0200, Skybuck Flying wrote:

>
warning C4146: unary minus operator applied to unsigned type, result still
unsigned.

?

I guess you have 32-bit ints with 2''s complement.
The C99 rationale (6.4.4.4.)says "Notwithstanding the general rule
that literal constants are non-negative, 3..." where the footnote
is "3 Note that -4 is an expression: unary minus with operand 4.".
INT_MAX is 0x7FFFFFFF, so a decimal constant of 0x80000000 doesn''t
fit in a signed int, and if INT_MAX == LONG_MAX, not even in a
signed long. In C89 this would cause it to have unsigned type.
Negating it yields UINT_MAX + 1 - 0x80000000 which is 0x80000000,
which doesn''t fit in a signed int.
Try using:
long a = -2147483647 - 1, for example MSVC #define''s INT_MIN this
way (but with parentheses around it). Note that in C89 no type is
*required* to be able to hold that value, so the program won''t be
portable everywhere. But using long will make it portable even on
systems with 16-bit int, provided they use two''s complement.
(Or INT_MIN if you mean that. If you have C99 maybe you want to
use INT32_MIN and declare a as an int32_t, these are defined in
<stdint.h>.)

--
Army1987 (Replace "NOSPAM" with "email")
"Never attribute to malice that which can be adequately explained
by stupidity." -- R. J. Hanlon (?)


这篇关于int a = -2147483648;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆