C:简单算术输出的确认
我能否确认以下 C 代码给出 b 的未定义结果:
unsigned a = 0;
int b = a - 1;
Can I confirm that the following C code gives undefined result for b:
unsigned a = 0;
int b = a - 1;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
(§6.3.1.3/3):“...结果是实现定义的,或者引发实现定义的信号。”
在典型的二进制补码硬件上,我期望结果为 -1。
请注意,结果是实现定义的,而不是未定义的。
(§6.3.1.3/3): "...either the result is implementation-defined or an implementation-defined signal is raised."
On typical twos-complement hardware, I'd expect the result to be -1.
Note that the result is implementation defined, not undefined.
当您将 unsigned 分配给 int 时,会发生隐式类型转换。所以,它不是未定义的行为。
Implicit type conversion takes place when you assigned unsigned to int. So, its not undefined behavior.
它才会始终给出值
仅当您想在在线 c 编译器 中查看时,
It always giving the values
only if you want to check it out in the online c compiler