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

Assuming int is 32 bits wide, `1 << 32` invokes UB.



Indeed it does.

(Spoiler: it prints uninitialized stack memory. A bit closer to demons flying out your nose than you'd expect!)


Fun. Basically, it decides that (due to UB) it can simply not materialize the argument and carry on.

On Darwin/x86_64, this actually means that it prints out bits from an "uninitialized" register, specifically %rsi in this case, since that's where the second argument should be (even for variadic functions).

Certainly a jarring failure mode! However, if updating your compiler causes you to run into this, you already have a bug in your code (one that clang -- arguably not forcefully enough -- already warns you of).




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: