News for hackers. Stuff that matters.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by msbarnett on Monday February 13, 2017 @10:18PM (#13640894)
> The compiler deduction is that the null test is redundant, but it's not actually redundant.

No. The compiler is forced to assume x isn't null, because int y = *x; has no meaning iff x IS null, so the compiler can't possibly generate any code to cover that case. There's no definition of that construct for the compiler to work off of that could possibly allow x to be null.

Blame the standard if you want, but you can't blame the compiler for not generating code to cover behaviour that you've made up in your head.

Re:I Do Not Know C: Short quiz on undefined behavior (2015) by cronjobber on Tuesday February 14, 2017 @04:18AM (#13642307)
Nope, "undefined" leaves the compiler perfectly free to just Do The Right Thing.
Re:I Do Not Know C: Short quiz on undefined behavior (2015) by vyodaiken on Tuesday February 14, 2017 @08:53AM (#13643471)
I didn't make it up in my head - I observed it in working code. Widely used working code. And the compiler is not at all forced to assume x is not null. The standard leaves it to the compiler writer to handle the case. Could the compiler perform sophisticated static analysis and reject the code under the standard? Yes. Could the compiler simply compile the code as written ? Yes. Could the compiler abuse the vagueness of the standard to produce an "optimization" that implements something the programmer specifically did not implement? I suppose. But that's poor engineering.