5 ms·
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.
by mnw21cam 4y ago
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...
- adgjlsfhk1 4y agoNope, the C spec is just really bad. The NULL check is allowed to be removed.
- mnw21cam 4y agoSo the pseudocode: if (p is not NULL) { dereference p } is UB? That's crazy, but not actually unbelievable.
- dllthomas 4y agoI 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.
- UncleMeat 4y agoThe poster is just completely wrong. A compiler is required to emit the branch in this case.
- tsimionescu 4y agoThere's no misunderstanding on your part, just some muddled thinking on my part for the first example.