Comment

Comment by dale_glass

I think something that is often missing in such posts is the appalling attitude towards undefined behavior in C compilers.

Yes, okay. You've been careful. You've checked you're not accidentally overflowing a buffer, traced things with valgrind, all that good stuff.

None of that stops the compiler from doing random bullshit such as this in the search for better optimization:

https://gcc.godbolt.org/#%7B%22version%22%3A3%2C%22filterAsm...

Personally, as a programmer I dread that sort of thing. I want code to work, not to try to figure out how a compiler could interpret my code in the most twisted way possible, like some sort of evil genie.

I think that's one area where modern compilers are going wrong -- fine combing the spec for loopholes in the attempt to optimize better results in code being compiled into something nobody in their right mind would have intended.

Edit: For extra fun, try adding a std::cout to NeverCalled() -- it gets even more interesting.

parent dale_glass 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton