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++

  • merc@sh.itjust.works
    link
    fedilink
    arrow-up
    26
    ·
    6 months ago

    “C++ compilers also warn you…”

    Ok, quick question here for people who work in C++ with other people (not personal projects). How many warnings does the code produce when it’s compiled?

    I’ve written a little bit of C++ decades ago, and since then I’ve worked alongside devs who worked on C++ projects. I’ve never seen a codebase that didn’t produce hundreds if not thousands of lines of warnings when compiling.

    • jkercher@programming.dev
      link
      fedilink
      English
      arrow-up
      13
      ·
      6 months ago

      You shouldn’t have any warnings. They can be totally benign, but when you get used to seeing warnings, you will not see the one that does matter.

    • nroth@lemmy.world
      link
      fedilink
      arrow-up
      9
      ·
      6 months ago

      0 in our case, but we are pretty strict. Same at the first place I worked too. Big tech companies.

    • dejected_warp_core@lemmy.world
      link
      fedilink
      arrow-up
      6
      ·
      6 months ago

      Ideally? Zero. I’m sure some teams require “warnings as errors” as a compiler setting for all work to pass muster.

      In reality, there’s going to be odd corner-cases where some non-type-safe stuff is needed, which will make your compiler unhappy. I’ve seen this a bunch in 3rd party library headers, sadly. So it ultimately doesn’t matter how good my code is.

      There’s also a shedload of legacy things going on a lot of the time, like having to just let all warnings through because of the handful of places that will never be warning free. IMO its a way better practice to turn a warning off for a specific line.. Sad thing is, it’s newer than C++ itself and is implementation dependent, so it probably doesn’t get used as much.

      • merc@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        6 months ago

        I’ve seen this a bunch in 3rd party library headers, sadly. So it ultimately doesn’t matter how good my code is.

        Yeah, I’ve seen that too. The problem is that once the library starts spitting out warnings it’s hard to spot your own warnings.

    • Ajen@sh.itjust.works
      link
      fedilink
      arrow-up
      4
      ·
      6 months ago

      My team uses the -Werror flag, so our code won’t compile if there are any warnings at all.

    • vivendi@programming.dev
      link
      fedilink
      English
      arrow-up
      4
      ·
      6 months ago

      Ignoring warnings is really not a good way to deal with it. If a compiler is bitching about something there is a reason to.

      A lot of times the devs are too overworked or a little underloaded in the supply of fucks to give, so they ignore them.

      In some really high quality codebases, they turn on “treat warnings as errors” to ensure better code.

      • merc@sh.itjust.works
        link
        fedilink
        arrow-up
        2
        ·
        6 months ago

        I know that should be the philosophy, but is it? In my experience it seems to be normal to ignore warnings.