4 ms·
This topic comes up semi-regularly here on HN but I think the underlying issue is that standards do not exist in a void, yet a certain group of people seem to t
by userbinator 7y ago
This topic comes up semi-regularly here on HN but I think the underlying issue is that standards do not exist in a void, yet a certain group of people seem to think that they do --- the fact that a standard "imposes no requirements" should really be taken to mean "think about what really makes sense", not "do whatever the fuck you want". Hence the "but we still complies with the standard!" defense from compiler authors when faced with perplexing results of UB is totally ignoring the reality and practicality of what a compiler is for. Note that the standard writers have even tried to give that hint, with the "behaving during translation or program execution in a documented manner characteristic of the environment" phrasing which is precisely what programmers are usually expecting, but it seems few actually took the hint.
- mpweiher 7y agoIIRC the C standard explicitly states that conformance to the standard is insufficient for having a compiler that is fit for purpose.
- pjmlp 7y agoThe best example are embedded platforms, full with extensions that probably will never be part of ISO C.
- giomasce 7y agoDifferent people have different ideas on what "makes sense". The point of a standard is to not have to use common sense, which is usually not common al all. So there is no point is saying that when the standard does not say anything you should use common sense. If the standard says nothing, you should just avoid relying of that thing. The compiler is not responsible for the quality of the source code. The programmer is. The compiler is responsible for the quality of the machine code, assuming that the source code is correct. It is good to have tools to check the quality of source code, but they are a different thing from compilers. Personally, I am happy that the compiler optimizes the code for me when I write correct C/C++ programs. If I make a mistake and inadvertently do UB, I take the responsibility, without shifting it on the innocent compiler.
- pjmlp 7y ago> The compiler is not responsible for the quality of the source code. The programmer is. The last 40 years have proven how well it works in practice, specially if one plugs some kind of networking into it. Taking the responsibility should be taken to the same liability level of other engineering disciplines, then it would be interesting to see how long the myth of only bad programmers write bad C will survive.
- comex 7y agoI don't know how much this actually affects your argument, since you seem to be making a more general statement, but for the record: it's extraordinarily rare for vulnerabilities to be caused by compiler optimizations specifically. I've heard of a few instances (BIND denial of service; Linux TUN bug becoming exploitable instead of a denial of service; IIRC something with Native Client), but they're interesting precisely because they're rare. So I'd say that one shouldn't oppose compiler optimizations directly because of the risk of security vulnerabilities, although of course the prevalence of vulnerabilities can still be evidence that C programmers are prone to mistakes in general.