Earlier quoted context omitted.
> Yes, that's the excuse. It's a bad excuse. I'm amazed that you find this to be a bad excuse, since it's what all optimizing compilers rely on to produce performant code. > I've not found ARC code to crash less, and if you remember the article, it is about code that cannot possible crash actually crashing due to ARC. The code crashes because you violated an invariant at some point of program execution. The way the C…
> [undefined behavior for optimization] Yes, I am aware that that is the excuse. It still is a terrible excuse. > because you violated an invariant at some point of program execution. Not true. The code in question is a callback, so my code is getting called by Apple code, and ARC dereferences a pointer it has no business de-referencing. May I remind you that the code that crashed due to a segfault was { return 0; }…
No, I generally don't, which is why I use a safer language like Swift most of the time (well, that, and the fact that I can take advantage of a nicer standard library). You put "safer" in quotes, because I don't think you quite understand how compiler optimizations are supposed to work. I think Chris Lattner's three part series, "What Every C Programmer Should Know About Undefined Behavior"[1], is a great explanation from a compiler writer for why dangerous optimizations have to exist. It certainly helped me when I was in a similar place as you, not quite understanding why the optimizer did seemingly stupid things.
Really, the crux of the issue is that every language has tradeoffs: you can program in assembly and know exactly what your program is doing, but you lose the portability and convenience of higher level languages. Then you have the C family of languages, where you get access to some higher level concepts at the cost of ceding control to a compiler. The compiler's job is to generate assembly that matches what you are trying to do in the most efficient way possible. Of course, if it did so too literally it would be very slow to account for every single "stupid" thing you could have done, so there are some general rules that are imposed that you must follow in order for the compiler to do what you want. Then, of course, we have the high-level languages which do account for every stupid thing you might do, and so can provide proper diagnostics.
[1] http://blog.llvm.org/2011/05/what-every-c-programmer-should-...