5 ms·
If anything I think they are written by people who are too smart --- theoreticians who care only about the standard and can't be bothered exercising common sens
by userbinator 5y ago
If anything I think they are written by people who are too smart --- theoreticians who care only about the standard and can't be bothered exercising common sense when the standard doesn't specify what to do.
http://blog.metaobject.com/2014/04/cc-osmartass.html http://blog.metaobject.com/2014/04/cc-osmartass.html
- beached_whale 5y agoThe example about signed overflow misses the point, on good code it results in a performance improvement. Similar for dereference of null pointers; it allows the compiler to remove visible successive checks(e.g if you call *ptr, then all further calls to ptr will not be null until it is written to). This makes it faster to express preconditions but let the compiler make safer code faster.
- halayli 5y agoYour definition of what's considered common sense is based on your sole understanding of computers. It's more like your intuition. Just because you don't understand something fully doesn't mean it's not common sense. It's very common that programmers don't bother reading the standard or attempt to understand the concept of an abstract machine. Programmers that know what they are doing tend not to be surprised by such nuances.
- userbinator 5y agoNo, I've read the standard. The "abstract machine" is, as its name implies, abstract. In reality, there are other concerns that are equally if not more important. That is the problem with compiler writers, ignoring those practical concerns. They prefer to downvote rather than face the reality of going outside their imaginary abstract machine world. "In theory, theory and practice are the same. In practice, they are not."
- josephcsible 5y agoThe C standard can be thought of as a bunch of minimum requirements that program authors and compiler authors have to follow. What you seem to be arguing is for compiler authors to go above and beyond what's required of them, so that you as a program author can get away with doing less than the minimum that's required for you.
- userbinator 5y agoMe and everyone who has been subject to this "abuse" by compiler-writers stuck in their fantasy world.... including Linus Torvalds: https://news.ycombinator.com/item?id=17242103 https://news.ycombinator.com/item?id=17242103
- Gibbon1 5y agoReminds me once saw an comment about optimizing on UB by a compiler maintainer for Microsoft. He pointedly said the gcc maintainers would do better to work on their crummy code generation.
- astrange 5y agoAren't gcc/clang significantly better than MSVC? They're certainly better at safe code with tools like asan, and at least they support C99.
- pjmlp 5y agoNot updated with Visual Studio 2019? C11 and C17 are supported, minus C99 features made optional in C11. ASan is now in the box. And Visual Studio definitly provides a better experience of coupling static analysis with code being written.
- astrange 5y agoI am a bit behind. Sounds like a good update, since before it was effectively just a C++ compiler that implemented parts of C when it was convenient.
- UncleMeat 5y agoAre those practical concerns universal and well aligned with the language's design goals?
- overgard 5y agoThis attitude drives me crazy. C was once a simple language, but now the only people that can write it "correctly" are compiler implementers, and if they fuck up your code, it's your fault. You know how Linus will practically murder anyone that breaks user space, even if user space is "wrong"? I wish compiler makers had the same ethos. BTW, go look at how many optimizations are explicitly disabled to compile the kernel without it breaking and then come back to me with how these are a good idea. One of the most critical pieces of software infrastructure in the world looks at how broken compilers are and says yeah, leave that junk out.
- josephcsible 5y agoWhat you want would basically prohibit all optimizations.
- overgard 5y agoYour point is the standard that "optimizations shouldn't fuck up working code" is unreasonable? What point is there to optimizing something thats wrong? So you can break things 10% faster?
- josephcsible 5y ago> Your point is the standard that "optimizations shouldn't fuck up working code" is unreasonable? By "working code", do you mean code that the standard and/or target implementation promise will do what you want, or do you mean code that just happened to do what you want the last time you tested it on your system? If you mean the latter, then yes.
- overgard 5y agoWhat percentage of code do you honestly think has no undefined behavior? (hint: hardly any). Are you fortunate enough to work in one of those code bases? Remember its not up to you to not write UB, its up to everyone that touches the code base. If you are stuck with UB, would you prefer a compiler that does the safe thing, or a compiler that unleashes dragons?