6 ms·
The original ANSI C committee had no idea about modern optimization pipelines. If people had continually pushed back against undefined behavior back then, there
by pcwalton 9y ago
The original ANSI C committee had no idea about modern optimization pipelines. If people had continually pushed back against undefined behavior back then, there's a good chance that by 2017 the result would have been that C would be dead, replaced by a language that allows for modern optimization techniques.
- Filligree 9y agoAnd would that be such a bad thing? How come we have languages like Rust that achieve almost the same speed while maintaining dramatically better safety, anyway?
- pcwalton 9y agoBecause type safety makes a lot of optimizations sound. C and C++ have to use undefined behavior rules to achieve a lot of optimizations that type safe languages can more easily perform. In fact, the optimization that the article is complaining about is really only a problem because C is not type safe.
- Filligree 9y agoSo that's my point. If C was those few percentage points slower, and died, then we'd have better languages sooner.
- kps 9y agoYou're the last person I'd have expected to make that sound like a bad thing. While benchmark games played a part in the modern ‘undefined behavior’, I'm not so sure that it would made much difference to adoption of the language. Consider Linus Torvald's well-known rant as a point in the opposite direction. In the universe where ‘undefined behaviour’ had been clearly specified as ‘what you write is what you get’, C might have gone to consistent use of optimization-enabling annotations, following ‘const’ (and later ‘restrict’). Along those lines, ‘volatile’ was ANSI's other big mistake, as creating it broke existing code; I now think that should have been the default, with fragile-optimizable status being explicitly indicated by extending the use of ‘register’ keyword.
- pcwalton 9y agoIt's not just benchmark games. It's people's real-world code. Look at how often folks on HN complain that the Web platform is useless because JS is slow. C without optimizations is just as slow if not slower. Compiler optimizations are so good that people don't realize how much they rely on them. Linus was wrong when he complained about the compiler treating null dereference as undefined behavior. This is a very important optimization, because it allows the compiler to omit a lot of useless code in libraries. Often times, the easiest way to prove that "obviously" dead code can never be executed is to observe that the only way it could be executed is for null to be dereferenced. Opt-in optimization keywords wouldn't scale to the sheer number of optimizations a modern compiler framework performs. Restrict hasn't been a success because it's too subtle of an invariant. It's the kind of thing compiler authors, not application developers, should be thinking about.
- sillysaurus3 9y agoThis is an important point, and it's why the "C should die" crowd is hard to take seriously. They've even started labeling people who use C as somehow morally suspect, as if we're bad people for choosing to use an unsafe language. We're knowingly putting people in danger! Right. It's strange that the word "unsafe" has tainted people's thoughts so dramatically. Like calling torrenting music "piracy."
- pjmlp 9y agoIf one don't follow the High Integrety, CERT, MISRA standards, validated with tools like LDRA. Or at very minimumm compiling with warning enabled as errors, with a continuous build breaking on static analysers errors, then yes.
- pcwalton 9y agoI'm not endorsing C. Don't use C for anything you need to be secure.
- deleted 9y ago[deleted]
- thriftwy 9y agoSounds like win-win to me! C would be dead. We will have a sound low-level language suitable for optimization. Now, if we throw in C++ eradrication...
- morecoffee 9y agoIt would have been much more prudent if the committee defined the behavior in a way amenable to optimization, rather than asking for a blank check.
- belovedeagle 9y agoThey did. "Undefined" doesn't mean "unconsidered by the committee", it means "do what you must for optimization".
- iainmerrick 9y agoWhat language do you think would have replaced it? It seems to me that C had already won as the de facto systems language, long before any of these "modern optimisation techniques" cropped up. Optimisations that make it harder to use the language safely are downright dangerous in my book.
- pjmlp 9y agoI would have been happy with Modula-2, Ada or Object Pascal as basis. But better yet would have been Modula-3 or Active Oberon.
- iainmerrick 9y agoI hear very good things about Ada, aside from its unfriendly old-fashioned syntax.
- pjmlp 9y agoSome of us do enjoy verbose explicit syntax instead of hieroglyphs. :) Quite helpful when maintaining unknown code in big corp projects.
- voidmain 9y agoAs others have said, if C were dead by now that would be great. But I'm pretty skeptical, to be honest. I've been working on one or another high-performance C or C++ program for most of the past 20 years. I can't ever remember getting a really substantial speed improvement from upgrading the compiler for an important platform, because anything the old compiler did badly that really hurt program performance had already been avoided, either before or after seeing it in profiling results. I'm sure that if you took C code developed on a modern compiler and compiled it with a 90s compiler, it would be slower. But I doubt the software ecosystem would actually be drastically slower if optimizer technology hadn't advanced significantly since 1995, and everything had been developed under that constraint. And I don't think every single advance in optimization since 1995 is dependent on degenerate transformations of undefined behavior.