UINT_MAX + 1等于什么? [英] UINT_MAX + 1 equals what?

查看:1205
本文介绍了UINT_MAX + 1等于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是C语言为 UINT_MAX + 1U 定义的行为?如何安全是假设它是零?

What is the defined behavior in C for UINT_MAX + 1u? How safe is to assume it is zero?

推荐答案

从标准(C11,6.2.5 / 9,重点煤矿):

From the standard (C11, 6.2.5/9, emphasis mine):

[...]在无符号操作数可以永远不会溢出的一种计算,
   因为不能再通过psented $ P $结果的生成的无符号整数类型
  减小模数比,可以是在一个最大值大的数目
  再由结果类型psented $ P $

[...] A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.

如果 UINT_MAX 10

(10 + 1) % (10 + 1) == 0

所以,是的,它是安全的假设它是零。

So, yes, it's safe to assume it's zero.

这篇关于UINT_MAX + 1等于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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