Which will probably be never.

  • nexussapphire@lemm.ee
    link
    fedilink
    English
    arrow-up
    4
    arrow-down
    2
    ·
    4 months ago

    I forgot to assign a variable, now it crashes %5 of the time. It’s wild how c doesn’t default variables to null or something.

    • Endmaker@ani.social
      link
      fedilink
      English
      arrow-up
      14
      ·
      edit-2
      4 months ago

      default variables to null or something

      That is such a bad idea. Better to have the compiler warn you about it like in Rust, or have the linter / IDE highlight it.

      • nexussapphire@lemm.ee
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 months ago

        If it’s going to compile without any warnings I’d rather the app crash rather than continue execution with rogue values as it does now.

        There is so much room for things like corrupted files or undocumented behavior until it crashes. Without the compiler babysitting you it’s a lot easier to find broken variables when they don’t point to garbage.

        • zaphod@sopuli.xyz
          link
          fedilink
          arrow-up
          3
          ·
          4 months ago

          Just enable all compiler warnings (and disable the ones you don’t care about), a good C compiler can tell you about using unassigned variables.

          • nexussapphire@lemm.ee
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            4 months ago

            Still learning, they just covered compiler flags in cs. They didn’t go into detail yet though.

            Edit: I’ve used python for years and they have something equally dumb. You can have a function in a massive application that is broken and the moment it’s called, the application crashes.

            At any other point the application will just run as if nothing is wrong even though python evaluates everything at runtime. I’m sure they can’t do much because the initial launch would be slow.

    • CodeMonkey
      link
      fedilink
      arrow-up
      9
      ·
      edit-2
      4 months ago

      C does exactly what you tell it, no more. Why waste cycles setting a variable to a zero state when a correct program will set it to whatever initial state it expects? It is not user friendly, but it is performant.

      • marcos@lemmy.world
        link
        fedilink
        arrow-up
        7
        ·
        4 months ago

        Except that this is wrong. C is free to do all kinds of things you didn’t ask it to, and will often initialize your variables without you writing it.

        • nexussapphire@lemm.ee
          link
          fedilink
          English
          arrow-up
          1
          ·
          4 months ago

          Machine code would be a better example of what he’s talking about imo. Not an expert or anything of course.

          • marcos@lemmy.world
            link
            fedilink
            arrow-up
            3
            ·
            4 months ago

            Odds are that your computer doesn’t export any language where it will do exactly as you say (amd64 machine code certainly won’t execute exactly as written). And how much difference it makes varies from one language to another.

            But the specific example from the OP, of uninitialized variables, is one of those cases where the C spec famously goes completely out of line and says your code can do whatever, run with a random value, fail, initialize it, format your hard drive, make a transaction on your bank account… whatever.

            • Hack3900@lemy.lol
              link
              fedilink
              arrow-up
              2
              ·
              4 months ago

              Coding in C but if I don’t initialize a Variable the compiler formats my drive! (Not Clickbait)

      • nexussapphire@lemm.ee
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 months ago

        It wouldn’t be that much processing compared to the rest of the app. It would lot more efficient than running an effectively infinite loop or arithmetic on an arbitrarily large number as a result of an unsigned variables.