unsigned int size overflow [英] unsigned int size overflow

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

问题描述




在我的函数中,我收到一个unsigned int值,如果它超过一个限制,我需要检查



例如,

limit = 1000;


检查是这样执行的:

if(limit< inputValue)

{

//这样做

}


在所有情况下,这都可以,但FFFF FFFF除外。在这种情况下,

limit< inputValue返回TRUE,而不是FALSE。

这是由于溢出......我能为此做些什么。将是一个类型铸造

帮助吗?

解决方案

ma ********* @ gmail.com 写道:


>




在我的函数中,我收到一个unsigned int值,我需要检查

如果是超过限制。

比如说,

limit = 1000;


检查是这样执行的:


if(limit< inputValue)

{

//这样做

}


在所有情况下,除了FFFF FFFF之外,这都可以正常工作。在这种情况下,

limit< inputValue返回TRUE,而不是FALSE。

这是由于溢出......我能为此做些什么。会不会有类型铸造

的帮助?



确保(限制)是类型(unsigned int)。


我怀疑是签名/未签名的错误匹配,

虽然我无法确切地知道它将如何运作

给你所看到的东西。


-

pete


8月17日下午6:59,pete< pfil ... @ mindspring.comwrote:


marydeep ... @ gmail.com写道:




在我的函数中,我收到一个unsigned int值,如果值大于限制,我需要检查


例如,


limit = 1000;


检查执行如下:


if(limit< ; inputValue)

{

//这样做

}


在所有情况下,这都可以,但FFFF FFFF除外。在这种情况下,

limit< inputValue返回TRUE,而不是FALSE。

这是由于溢出......我能为此做些什么。会不会有类型铸造

的帮助?



确保(限制)是类型(unsigned int)。


我怀疑是签名/未签名的错误匹配,

虽然我无法确切地知道它将如何运作

给你所看到的东西。


-

pete-隐藏引用文字 -


- 显示引用文字 -



限制是未签名的..我做了类型转换,虽然没有类型

不匹配......并且它有效:))

非常感谢:)


ma ********* @gmail .com 写道:


限制是未签名的..我做了类型转换,虽然没有类型

不匹配..它工作了:))



这可能意味着你已经解决了问题,没有解决它。

发布你的实际代码,缩小到一个示例,显示完整声明的实际

问题如果你想要一个明确的解决方案。


Richard


Hi,

In my function, I receive a value as unsigned int, and i need to check
if it is greater than a limit.
say for example,
limit = 1000;

the checking is performed like this:

if(limit< inputValue)
{
//Do this
}

In all cases this works fine, except FFFF FFFF. In this case,
limit<inputValue returns TRUE, instead of FALSE.
Is this due to overflow..what can i do for this. will a type casting
help?

解决方案

ma*********@gmail.com wrote:

>
Hi,

In my function, I receive a value as unsigned int, and i need to check
if it is greater than a limit.
say for example,
limit = 1000;

the checking is performed like this:

if(limit< inputValue)
{
//Do this
}

In all cases this works fine, except FFFF FFFF. In this case,
limit<inputValue returns TRUE, instead of FALSE.
Is this due to overflow..what can i do for this. will a type casting
help?

Make sure that (limit) is of type (unsigned int).

I''m suspecting a signed/unsigned mistmatch,
though I can''t see exactly how it would work out
to give you what you are seeing.

--
pete


On Aug 17, 6:59 pm, pete <pfil...@mindspring.comwrote:

marydeep...@gmail.com wrote:

Hi,

In my function, I receive a value as unsigned int, and i need to check
if it is greater than a limit.
say for example,
limit = 1000;

the checking is performed like this:

if(limit< inputValue)
{
//Do this
}

In all cases this works fine, except FFFF FFFF. In this case,
limit<inputValue returns TRUE, instead of FALSE.
Is this due to overflow..what can i do for this. will a type casting
help?


Make sure that (limit) is of type (unsigned int).

I''m suspecting a signed/unsigned mistmatch,
though I can''t see exactly how it would work out
to give you what you are seeing.

--
pete- Hide quoted text -

- Show quoted text -

Limit was unsigned..I did a typecast, though there was no type
mismatch...and it worked :))
Thanks alot :)


ma*********@gmail.com wrote:

Limit was unsigned..I did a typecast, though there was no type
mismatch...and it worked :))

This may mean that you have papered over the problem, not solved it.
Post your actual code, whittled down to an example that shows the actual
problem with complete declarations, if you want a definitive solution.

Richard


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

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