Hacker News new | past | comments | ask | show | jobs | submit login

It is often instructive and useful to look at the behavior of real implementations, not just the idealized behavior given by the standard.



Indeed - sometimes you run into something and think "that shouldn't have worked", and it's useful to understand why.


When compiled with -O3 using g++ it returns 0 8. Compiler will use undefined behavior to optimize.


There's a fun example with clang where you can have two pointers where:

    x == y
But:

    *x != *y
It involves invoking undefined behavior by using a pointer after it's been freed and arranging for a new pointer at the exact same location. Clang cached the contents of the old pointer and uses it in the comparison.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: