10 ms·
But did you verify it never overflows? I think it is much harder to get that right without language (or compiler) support. Keep it mind that overflow is as seve
by lifthrasiir 7y ago
But did you verify it never overflows? I think it is much harder to get that right without language (or compiler) support. Keep it mind that overflow is as severe as memory bug in C/C++ due to the unforgiving nature of UBs in those languages.
- kazinator 7y agoHad integers wrapped in a class, yes. > that overflow is as severe as memory bug in C/C++ In practice, it isn't. In many traditional compilers it has predictable behavior (two's complement wrapping), if we're not talking about floating-point overflow. Some programs explicitly rely on it. Compiler support can be provided for those programs. It's simply not in the same category as memory corruption bugs. Of course, ISO C and C++ have just one category for undefined! However, note that "undefined behavior" is a formal term which extends over beneficial areas such as documented extensions and the use of third-party libraries and headers.
- bsder 7y ago> Had integers wrapped in a class, yes. Okay, you were serious about safety. Congratulations, you are the first one I have ever come across. I have never seen anyone else wrap integers in a class in order to use them with stable semantics.
- kazinator 7y agoThat was practically a poster example to sell C++. Look, you can overload operators and get arrays with bounds checking, integers that trap overflows and so on. Twenty years ago, C++ was still hot and there was a lot of interest in all sorts of techniques. Books, seminars, papers, blogs, you name it. There is a way to use C++ template partial specialization to mimic the built-in conversion rules, like "int op long" promoting the left operan to "int". You can mirror the language in itself and bend the rules.