Comment

Comment by kibibu

You got so worked up about specific examples that you missed the point somewhat.

Consider this mini example:

    void myfunc (int * p)  {
     int t = *p;
     if(p == NULL) { return;}
     *p = t + 1;
   } 
Accessing p before null check is undefined, and causes compilers to deduce that the null check isn't required. It can therefore be stripped, which most programmers would find very surprising.

Edit: yes, the replies are right, I meant to dereference *p rather than just copy the pointer. Fixed and somewhat simplified.

I was trying (badly) to remember this example: http://blog.llvm.org/2011/05/what-every-c-programmer-should-...

parent kibibu 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton