News for hackers. Stuff that matters.
Re:Falsehoods programmers believe about undefined behavior by mnw21cam on Monday November 28, 2022 @09:51AM (#33774299)
Presumably (and really don't take my word for this - I'm a Java bod) the p dereference needs to come before the p NULL check for the p NULL check to be ignored. (Otherwise, how can a NULL check protect a dereference.) And therefore, the NULL check would be unreachable as well, and therefore never executed and not relevant.

Please correct my misunderstanding...

Re:Falsehoods programmers believe about undefined behavior by adgjlsfhk1 on Monday November 28, 2022 @10:03AM (#33774464)
Nope, the C spec is just really bad. The NULL check is allowed to be removed.
Re:Falsehoods programmers believe about undefined behavior by mnw21cam on Monday November 28, 2022 @11:03AM (#33775271)
So the pseudocode:

  if (p is not NULL) {
    dereference p
  }
is UB? That's crazy, but not actually unbelievable.
Re:Falsehoods programmers believe about undefined behavior by dllthomas on Monday November 28, 2022 @11:21AM (#33775518)
I am not certain of the language lawyer side of it, but no reasonable (or even moderately unreasonable) compiler would omit that check because of the guarded behavior; way too much code would break, probably including that compiler's standard library.
Re:Falsehoods programmers believe about undefined behavior by UncleMeat on Monday November 28, 2022 @12:15PM (#33776302)
The poster is just completely wrong. A compiler is required to emit the branch in this case.
Re:Falsehoods programmers believe about undefined behavior by tsimionescu on Tuesday November 29, 2022 @03:39AM (#33785094)
There's no misunderstanding on your part, just some muddled thinking on my part for the first example.