Type Punning in C and C++

I had a bug that took me a while to track down. The problem was type punning. A pointer cast worked fine at -O0 and silently broke at -O2. The C vs C++ distinction here is genuinely treacherous, and most blog posts on the topic get it wrong.
34 points by ingve 30 days ago blog.pwkf.org 16 comments

Summary

Type punning can lead to tricky bugs, especially when compiler optimizations are involved. This article shares a personal experience with a specific issue encountered in C and C++, highlighting the nuances that many resources overlook.

Comments (16 of ) ⌛

Loading more comments... ⌛
Scroll down to load more comments
No comments available.
Type to search HN and engineering blog articles
Press Escape to close  |  ↑↓ to navigate  |  Enter to open