News for hackers. Stuff that matters.
Re:A bug story: data alignment on x86 by scott_s on Monday November 07, 2016 @02:07PM (#12893888)
I believe you are confusing undefined behavior and implementation defined behavior. Undefined behavior is illegal under all compilers, and all bets are off if you do it. Implementation defined behavior is always legal, but different compilers are allowed to do different things.
Re:A bug story: data alignment on x86 by Sagiri on Tuesday November 08, 2016 @12:53PM (#12902379)
I'm not.

Undefined behavior is 'anything goes'. An implementation can choose a particular behavior that you can rely on for a particular case of UB, because, if the only rule is that 'anything goes', it doesn't violate that rule.

I'll admit that compilers don't generally do that - because specifying it could lead to fewer optimizations. But I did say "if", and there's no reason they couldn't do so in principle.

One could imagine a compiler with an extremely strict debug mode that traps on a number of situations that the standard deems undefined behavior via a segfault, in order to help people avoid relying on UB. Again - saying something like "casting misaligned pointers causes a segfault on [system]" would in no way violate a standard that says "casting misaligned pointers can do anything", because segfaulting falls under the umbrella of anything.

I think you're misinterpreting the fact that the results of undefined behavior can be ignored by a compiler for a requirement that it must be ignored by a compiler.

Re:A bug story: data alignment on x86 by startling on Monday November 07, 2016 @06:48PM (#12896363)
Undefined behavior is not illegal. The compiler can do anything with undefined behavior, including exactly what the author expected.
Re:A bug story: data alignment on x86 by scott_s on Tuesday November 08, 2016 @09:42AM (#12900578)
It is illegal, for any reasonable definition of illegal. See my comment from earlier in the year: https://news.ycombinator.com/item?id=10840497
Re:A bug story: data alignment on x86 by startling on Tuesday November 08, 2016 @06:11PM (#12904794)
"Illegal" seems stronger to me than "not strictly conforming", I guess (and so does "well-formed", for that matter). But I think we basically agree.