Which will probably be never.

  • nexussapphire@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 month 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.

    • CodeMonkey@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      1 month 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
        1
        ·
        1 month 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.

    • Endmaker@ani.social
      link
      fedilink
      English
      arrow-up
      0
      ·
      edit-2
      1 month 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
        0
        ·
        1 month 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
          1
          ·
          1 month 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.