是否可以使用C ++访问CPU中的溢出标志寄存器? [英] Is it possible to access the overflow flag register in a CPU with C++?

查看:85
本文介绍了是否可以使用C ++访问CPU中的溢出标志寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行数学运算(例如,将两个整数相乘)之后,是否可以使用C ++访问CPU中的溢出标志寄存器?如果不是,还有什么其他快速方法可以检查溢出?

After performing a mathematical operation, for say, multiplying two integers, is it possible to access the overflow flag register in a CPU with C++ ? If not what are other fast ways to check for an overflow ?

推荐答案

不,通常是不可能的.某些CPU甚至没有这样的标志(例如MIPS).

No, generally it's impossible. Some CPUs don't even have such a flag (e.g. MIPS).

其中一条评论中提供的链接给您有关如何执行溢出检查的想法.

The link provided in one of the comments will give you ideas on how you can do overflow checks.

请记住,在C和C ++中,带符号整数溢出会导致未定义的行为,并且从法律上讲,您不能在此之后执行溢出检查.您要么需要使用无符号算术,要么在算术运算之前进行检查.

Remember that in C and C++ signed integer overflows cause undefined behavior and legally you cannot perform overflow checks after the fact. You either need to use unsigned arithmetic or do the checks before arithmetic operations.

这篇关于是否可以使用C ++访问CPU中的溢出标志寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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