4 ms·
> It's very irresponsible to treat situations that are coding mistakes as "let's assume there is no mistake and just optimize". Well, that's the C philosophy,
by MaxBarraclough 8y ago
> It's very irresponsible to treat situations that are coding mistakes as "let's assume there is no mistake and just optimize".
Well, that's the C philosophy, and it's part of the reason it's so fast. As I've said repeatedly throughout this thread, if you want a safe language, why are you using C?
If the compiler detects undefined behavior, it should of course issue a loud warning to the programmer, but that's not the issue. The issue is that the compiler assumes absence of UB and optimises accordingly, spending relatively little effort investigating whether UB is actually present.
If that's what you want, use a proper static-analysis tool. (They really deserve more use!)
- kazinator 8y agoThe compiler has deduced that a comparison of a pointer to null makes no sense, because it was dereferenced; if that code is reached, the comparison will always be true. That should be diagnosed, just like, say, an unsigned-type > 0 comparison that is always true. > why are you using C? For detailed control of the machine with minimal run-time support, without resorting to assembly language. Basically, the original reasons for C, before all this historic revisionism. I want reasonable speed: good use of registers and basic optimizations like jump threading and peephole code improvements. Optimization in C is otherwise the job of the programmer. The machine code should more or less follow from the calculations that are written in the source, and every memory access through pointers should be there, in the order it appears. The "trust the programmer" mantra never meant "trust that there is no undefined behavior" but simply "trust that the programmer put every every expression in place for a reason and just translate it to machine code".
- mpweiher 8y ago>> why are you using C? > For detailed control of the machine with minimal run-time support, without resorting to assembly language. Exactly. C is about low-level control. That's why operating systems are written in C and numeric codes in FORTRAN, and not the other way around. Speed is something C enables for the programmer to obtain via the low-level control, not something it provides by trying to read your mind. > Basically, the original reasons for C, before all this historic revisionism. Yes, the revisionism is really, really frustrating. Too bad I can only upvote you once.
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]