ç赋值不是数据类型的范围更大 [英] C assigning values greater than data type ranges

查看:138
本文介绍了ç赋值不是数据类型的范围更大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C的int类型可以有以下的 +已经值范围2,147,483,647

https://msdn.microsoft.com/en-IN/library/s3f49ktz.aspx

我想知道会发生什么,如果我分配值大于int可以支持,这些值是如何截断或究竟是什么存储,如果我这样做

I would like to know what happens if I assign values greater than int can hold, how the values are truncated or what is exactly stored, if I do this

INT VAR = 2147483648;

推荐答案

当你引用链接的说法,这是的错误即可。然而,链接页面的状态正确,它是适用于该具体实施。阅读为的最小距离标准 的标准类型。

As you cited the linked statement, it is wrong. However, the linked page states correctly that it is valid for that specific implementation. Read the standard for minimum ranges of the standard types.

实际尺寸在 limits.h中。你不应该依赖于其他任何东西。如果你需要一个特定的大小,使用 stdint.h 类型。

Actual sizes are in limits.h. You should not rely on anything else. If you need a specific size, use stdint.h types.

如果您分配一个符号值的一个对象也不能容纳该值,结果是的实现定义
一个适当的编译器允许启用此类问题的警告! - 使用它们

If you assign a signed value to an object which cannot hold that value, the result is implementation defined. A proper compilers allows to enable warnings for such issues - use them!

OTOH,对于一个无符号的价值,这是非常明确的(相同标准的部分)。简单地说,高位将被忽略。

OTOH, for an unsigned value, it is very well defined (same section of the standard). Simply put, the upper bits are just ignored.

这篇关于ç赋值不是数据类型的范围更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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