3 ms·
Because they aren't C. I think it's not just that "undefined behavior can be optimized" in some abstract sense but that in particular C has the problem that its
by jerf 11y ago
Because they aren't C. I think it's not just that "undefined behavior can be optimized" in some abstract sense but that in particular C has the problem that its undefined behavior is where a lot of optimizations live. This is due to a combination of the language being very old now, and the hardware world having moved on a lot since it was (half-)specified.
I really don't consider this a criticism of C per se or its designers. It is unreasonable to expect that a language specified in the 1970s would be tuned for either modern processors or have the benefit of an additional 40 years of collective experience. But it is, nevertheless, true.
(It's part of why my position is very much that this entire approach just won't work. C is pretty much what it is; it can not be changed. It is literally easier to use another language than to try to specify a "friendly C" in 2016. And I don't say that because I don't know how large a task it is to start writing code in another language; I say that because people are really underestimating how much work Friendly C will take. I suggest that everyone observe that all who have now seriously tried to sketch what this would look like have immediately given up and totally surrendered. This means something.)
- pjmlp 11y agoThere is another reason for C's undefined behavior. Back when the language was being standardize, there was way more hardware diversity than there is now and C implementations outside UNIX, even K&R ones, had lots of semantic differences. As no compiler vendor involved in the first ANSI C process wanted to give up on their semantics, all of them were swept into "undefined behavior".
- jerf 11y agoKinda part of what I meant by "the hardware world having moved on a lot". I mean, I can hardly think of a way in which it is the same world, except perhaps a vague von-Neumann-esque architecture still being used, but even that's a lot different than it used to, thanks to the way that nowadays even assembler code is really just a specification to the CPU, rather than an execution plan, since the CPU recompiles it to internal microcode and just does whatever it likes instead on the fly. Almost nothing is the same as it was back then.