I don’t think that casting a range of bits as some other arbitrary type “is a bug nobody sees coming”.

C++ compilers also warn you that this is likely an issue and will fail to compile if configured to do so. But it will let you do it if you really want to.

That’s why I love C++

    • Valmond@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      2 months ago

      You use it to “pack” bitfields, bytes etc together in structs/classes (wo functions), otherwise the computer usually align every variable on a 32bit boundary for speed.

        • Valmond@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          2 months ago

          With say a 3bit int, then a 2bit int and various char, int etc and so on you did have to use the pragma with gcc & visual around 2012 at least