10 pointsby Quentak8 hours ago1 comment
  • Panzerschrek4 hours ago
    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.

    • Frieren3 hours ago
      > 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.

      • Panzerschrek3 hours ago
        > C++ is just fine

        No it isn't. Using undefined behavior for things which can be implementation-defined behavior instead is harmful. It creates more space for bugs and security vulnerabilities.

        • Frieren2 hours ago
          C++ was designed as an universal way of writing low level system code. It has some abstractions above C, but still allowing for all kinds of optimizations. (Think using a class vs a template, similar abstraction different impact).

          To use C++ to code user programs is the actual mistake.

          Think about assembly. Should assembly also be safe in all calls? That will make everything slower, and consume way more energy. Will you blame assembly if people used it to create a phone app and it had memory leaks? Or will you blame the developer for using assembly in the first place?

          C++ is a tool designed for a range of purposes. There is a push to make it an universal language that makes everything well. But engineering is about making compromises.

          For your use, C++ may be the wrong language. I do not disagree with you. But maybe you should be using another language instead. Or we should create a new language that fills the sweet spot that C++ covers, and then evolve C++ to be the safe language that you want. One way or another, it is a compromise.