← Back to context

Comment by Dylan16807

6 days ago

And every single developer is supposed to memorize GCC's optimizations so they never make a change that will optimize wrong?

Nah, treating undefined behavior as predictable is a fool's errand. It's also a shot in the dark.

What is that about memorization? I just need to know where the information is so I can refer to it later when I need it (and possibly archive them if they're that important).

  • If you're not trying to memorize the entirety of GCC's behavior (and keeping up with its updates), then you need to check if your UB is still doing what you expect every single time you change your function. Or other functions near it. Or anything that gets linked to it.

    It's effectively impossible to rely on. Checking at the time of coding, or occasionally spot checking, still leaves you at massive risk of bugs or security flaws. It falls under "I can't predict".

    • In C, strings are just basic arrays which themselves are just pointers. There’s no safeguards there like we have in Java, so we need to write the guardrails ourselves, because failure to do so result in errors. If you didn’t know about it, a buffer overflow may be unexpected, but you don’t need to go and memorize the entire gcc codebase to know. Just knowing the semantics is enough.

      The same thing happens with optimization. They usually warns about the gotchas, and it’s easy to check if the errors will bother you or not. You dont have to do an exhaustive list of errors when the classes are neatly defined.

      1 reply →