• quilan@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    8 months ago

    Aww, was hoping for some insight on global variable initialization order. It’s something I’ve been curious about how different vendors order things with linking.

    • addie@feddit.uk
      link
      fedilink
      arrow-up
      4
      ·
      8 months ago

      “Essentially at random, and it may change with build flags, compiler version updates, static v. dynamic linking, and who knows what else?” Can’t rely on it, I’m afraid. What you can rely on is static init of local variables:

        static auto this_is_safe = QuilanType{};
        return this_is_safe;
      }```
      ... Which will always give you a properly initialised 'global'.
      • brisk
        link
        fedilink
        arrow-up
        2
        ·
        8 months ago

        My C brain does not like static auto