digitalmars.D - Re: Apparently unsigned types really are necessary
Era Scarecrow <rtcvb32 yahoo.com> writes:
Would it be sane to add integer overflow/carry runtime checks in -debug builds? This could probably solve such issues, but we'd need some means to avoid this checks when necessary.
I have asked before regarding getting some standard way to hold these values after an arithmetic operation. Comes down to problems making it portable (basically). Being as these are taken directly out of C's view of how to handle arithmetic (Which ignores the hardware's obvious view) we need to look at it twice. First, normal computations where we ask for a squared value, or something for a project we are working on that needs a good value. These are situations where overflow, carry, and where such effects would screw with our results. These should have checks. The second is algorithms, PRNGs, encryption, checksums, which rely on the behavior as it is. We would need a way to specify which ints needed to be checked; Or if you want to go the other direction, specify which ones specifically don't. I think having the checks in the debug mode would be wonderful, for when you need it. It almost seems more likely a new struct type would be made that does those checks for you and is replaced during release with it's emulated type (Not too unlike SafeInt Microsoft was making).
Jan 22 2012
bearophile <bearophileHUGS lycos.com> writes:
Era Scarecrow:We would need a way to specify which ints needed to be checked; Or if you want to go the other direction, specify which ones specifically don't. I think having the checks in the debug mode would be wonderful, for when you need it.
If D will have some success, and it will be used a bit in situations where Ada is today used, then surely a D compiler will have checked signed and unsigned integrals. But there's also a need for a syntax to locally disable the checks. Bye, bearophile
Jan 22 2012