Join the discussion
Write your take first — we'll ask for email only when you're ready to publish.
- Hacker News
- A good example of C++ bizarre design decisions. The exact handing of float<->int conversions should use implementation-defined behavior instead, defining some cases to be UB just adds more traps with little to no performance benefits.
The same is true for bit-shifts greater than type bit size and negative bit-shifts.
by Panzerschrek - > bizarre design decisions
They are not bizarre but a good compromise between consistency and optimization for any possible existing and future CPU architecture.
What the author correctly points out to is that GSL implementation does not remove that undefined behaviour as it lacks the proper checks. And that is the problem as it does not fulfill its own documented guarantees.
tldr; C++ is just fine. The implementation in the library is wrong.
by Frieren - Undefined behavior was, in most cases, intended to encompass a point where different implementations behaved in reasonable ways. In case of overflow, some implementations wrapped, some saturated, some threw an exception, some jumped to an interrupt handler, and some returned 0. They made it undefined intending to encompass all of these. Notice they are all fairly reasonable (except for returning 0).
Later, stupid compiler writers decided that since the wording allows anything to happen, it also allows time travel or memory corruption. These are not reasonable, but they are allowed by the wording of the standard.
The standard should be fixed to say it returns an undefined value or activates an error handling mechanism. Nobody could argue that time travel is an error handling mechanism.
by inigyou - > They made it undefined intending to encompass all of these.
Why wouldn't implementation-defined behavior suffice in this case?
by aw1621107