8 ms·
I think this type of thinking is cynical and unhelpful. We complain that compiler technology is not keeping pace, then when they put in god knows how many hundr
by treehau5 11y ago
I think this type of thinking is cynical and unhelpful. We complain that compiler technology is not keeping pace, then when they put in god knows how many hundreds of hours of work improving, we complain when we might have to spend a few to go back through our programs and make sure everything's okay. We want everyone else to do the work for us.
- lmm 11y ago> We complain that compiler technology is not keeping pace Who was complaining about that? > when they put in god knows how many hundreds of hours of work improving, we complain when we might have to spend a few to go back through our programs and make sure everything's okay. We want everyone else to do the work for us. Their whole job is to compile our programs - what else is a compiler good for? I don't know who GCC's users are these days - people who care more about benchmarks than working code? Because that seems to be who they're optimising for. Then again I suppose that's the entirety of C/C++'s market these days.
- dave2000 11y agoAre you saying you have an example of valid c++ code which fails to compile, and that this problem is getting worse, or just that you get unexpected behaviour when write bad code?
- coldpie 11y agoCompiler bugs caused by optimizations aren't at all unheard of. We got bit by one recently: https://bugs.winehq.org/show_bug.cgi?id=38653 https://bugs.winehq.org/show_bug.cgi?id=38653 That said, I agree with treehau5.
- lmm 11y ago"Valid" in that the standard absolutely requires that compilers give them some particular meaning, no matter how rules-lawyery the compiler is? No. "Valid" in the sense that the intent is perfectly obvious to any reader? Yes, plenty. "bad"? No, unless you use the standard as your definition of good/bad.
- lomnakkus 11y ago> the intent is perfectly obvious to any reader So compilers need to judge what is "perfectly obvious to any reader", now? And you're willing to deal with the fallout of different compilers having different conceptions of "perfectly obvious"? That's... an ambitious project. Maybe your time would be better spent convincing the C++ committee to define some more behavior instead of leaving it undefined.
- lmm 11y agoThe C++ committee exists to standardise the behaviour that major compilers implement. Trying to get them to define behaviour where there isn't already at least broad support would be putting the cart before the horse.
- chriswarbo 11y ago> Their whole job is to compile our programs - what else is a compiler good for? I don't know who GCC's users are these days - people who care more about benchmarks than working code? Because that seems to be who they're optimising for. If all you want the compiler to do is make a working program, just disable all optimisations.
- wtetzner 11y agoIf you're not interested in performance, but are interested in working code, then why wouldn't you pick something other than C/C++?
- jabl 11y agoKnee-jerk rants aside, there is of course the underlying point that C and C++ have such wide scope for undefined and implementation-defined behavior that no mortal programmer can write a non-trivial C/C++ program that follows the standard to the letter. Whether it's possible to salvage C/C++ by specifying some safe subset (for some ideas towards this see e.g. Regehr's "safe C" or DJB's "boring C") without sacrificing too much performance remains to be seen. Another option, then, would be to start over from a clean slate, e.g. Rust. While most likely having less of an impact on the world at large, at least personally I find learning myself Rust more fulfilling than the prospect of fighting political battles in the ISOC committée. YMMV, of course. tl;dr: The above has all to do with the specification of the C and C++ languages rather than compiler writers attempt to exploit the spec to its fullest potential. So yeah, as long as "compiler goodness" is (marketing-wise at least) determined by SPECcpu scores, it's unfair to blame compiler writers for this mess.
- jjnoakes 11y agoThis is absolutely not true. I work with many C and C++ programmers, and we ship very large amounts of C and C++ code with a very high adherence to the standards.
- pdw 11y agoCan you name an open-source C or C++ project that you believe avoids undefined behavior? Because some people have spend serious time looking without success. E.g. http://blog.regehr.org/archives/1292 http://blog.regehr.org/archives/1292
- necessity 11y agoI cannot see the language being at fault in cases such as the ones pointed out by the article: > SQLite’s vdbe struct has a member called aMem that uses 1-based array indexing. To avoid wasting an element, this array is initialized like this: p->aMem = allocSpace(...); p->aMem--;
- 11y ago
- DannyBee 11y agoExcept, they do that too now, with undefined behavior sanitizer available in both llvm and gcc. Sure, it doesn't catch everything everything, but ...