UINT_MAX == INT_MAX可能吗? [英] UINT_MAX == INT_MAX possible?

查看:189
本文介绍了UINT_MAX == INT_MAX可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,


int和unsigned

int表示中的值位数是否正确?如果是这样,那么INT_MIN

可能是 - (INT_MAX + 1)(在数学意义上),即abs(INT_MIN)

在int或unsigned int中无法表示。还是保证

任何int值的大小都适合unsigned int?


Yevgen

Hey,

Is it correct that number of value bits in int and unsigned
int representation may be the same? If it is so, then INT_MIN
may be -(INT_MAX+1) (in mathematical sense), i.e. abs(INT_MIN)
is not representable in int or unsigned int. Or is it guaranteed
that magnitude of any int value fits in unsigned int?

Yevgen

推荐答案

Yevgen Muntyan说:
Yevgen Muntyan said:

嘿,


这个值的位数是否正确int和unsigned

int表示可能是一样的吗?
Hey,

Is it correct that number of value bits in int and unsigned
int representation may be the same?



int和unsigned int保证采用相同数量的

存储空间。在有符号类型中,其中一个位保留为符号位。

因此,如果您不将符号计为值位,则signed int有一个值

比unsigned int少。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

Both int and unsigned int are guaranteed to take the same amount of
storage. In the signed type, one of the bits is reserved as a sign bit.
Thus, if you don''t count sign as a value bit, signed int has one value
bit fewer than unsigned int.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


Richard Heathfield写道:
Richard Heathfield wrote:

Yevgen Muntyan说:
Yevgen Muntyan said:

>嘿,

int中的值位数是否正确和unsigned
int表示可能是一样的吗?
>Hey,

Is it correct that number of value bits in int and unsigned
int representation may be the same?



int和unsigned int保证采用相同数量的

存储空间。在有符号类型中,其中一个位保留为符号位。

因此,如果您不将符号计为值位,则signed int有一个值

比unsigned int少。


Both int and unsigned int are guaranteed to take the same amount of
storage. In the signed type, one of the bits is reserved as a sign bit.
Thus, if you don''t count sign as a value bit, signed int has one value
bit fewer than unsigned int.



仅当int中的填充位数相同且

unsigned时才会出现这种情况。总是这样吗?


Yevgen

This is only true if number of padding bits is the same in int and
unsigned. Is it always the case?

Yevgen


Yevgen Muntyan< mu *********** *****@tamu.eduwrites:
Yevgen Muntyan <mu****************@tamu.eduwrites:

Richard Heathfield写道:
Richard Heathfield wrote:

> Yevgen Muntyan说:
>Yevgen Muntyan said:

>> int和unsigned
int表示中的值位数是否相同是否正确?
>>Is it correct that number of value bits in int and unsigned
int representation may be the same?


int和unsigned int保证采用相同数量的存储空间。在有符号类型中,其中一个位保留为符号
位。因此,如果您不将符号计为值位,则signed int的值比unsigned int少一个。

Both int and unsigned int are guaranteed to take the same amount of
storage. In the signed type, one of the bits is reserved as a sign
bit. Thus, if you don''t count sign as a value bit, signed int has
one value bit fewer than unsigned int.



仅当int中的填充位数相同且

unsigned时才会出现这种情况。总是这样吗?


This is only true if number of padding bits is the same in int and
unsigned. Is it always the case?



它不一定是。


考虑一个支持有符号但不是无符号算术的CPU。这是不是很现实的
,但这是可能的。假设一个N位字大小。

然后int可能有N-1个值位和1个符号位,而unsigned int

可能有相同的布局,但是处理签名位作为填充

位。这给了我们UINT_MAX == INT_MAX。


这对签名的char与unsigned char不会发生,因为unsigned

char是特别禁止的填充位。


-

Keith Thompson(The_Other_Keith) ks ** *@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu / ~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

It needn''t be.

Consider a CPU that supports signed but not unsigned arithmetic. It''s
not very realistic, but it''s possible. Assume an N-bit word size.
Then int might have N-1 value bits and 1 sign bit, and unsigned int
might have the same layout, but treating the sign bit as a padding
bit. This gives us UINT_MAX == INT_MAX.

This can''t happen for signed char vs. unsigned char, because unsigned
char is specifically forbidden to have padding bits.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于UINT_MAX == INT_MAX可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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