Newsgroups: comp.arch Path: csiph.com!feeder.erje.net!1.us.feeder.erje.net!newspeer1.nac.net!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!kithrup.com!mrs From: mrs@kithrup.com (Mike Stump) Subject: Re: The freedom that give us C++ and C Message-ID: Date: Mon, 18 Jan 2016 11:45:40 GMT References: <77bce982-05c1-46ce-97f4-a30e6310ff58@googlegroups.com> <2016Jan14.151802@mips.complang.tuwien.ac.at> Organization: Kithrup Enterprises, Ld. X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Lines: 104 Xref: csiph.com comp.arch:32839 In article <2016Jan14.151802@mips.complang.tuwien.ac.at>, Anton Ertl wrote: >mrs@kithrup.com (Mike Stump) writes: >I don't want tested and working programs to break when compiled with a >new version of the compiler and the same compiler flags. You want erroneous programs to behaves exactly the same as well. You left that out, that that's the onlything in contention. >One might think that this is the goal of any serious language >implementor, but that's obviously not the case for the GCC and LLVM >maintainers. No. We treat buggy programs as buggy and don't try and cater to bugs or people that can't program non-buggy software. I agree, it sucks to be on the receiving end of that. >I actually want C compilers to be (minimally) consistent in their >behaviour. No, we are already that. We consistently treat undefined behaviour as buggy and undefined. You don't want that. Mere consistancy is necessary for you, but not sufficient. You want to be able to define what the compiler does to the exclusion of others that want to define what the compiler does. >In particular, consistent across compiler versions on the same >platform, and consistent between cases where the compiler knows >nothing about concrete values and where it knows something. Again, necessary, but not sufficient for you. >So it's not my favourite definition of standard-undefined behaviour >in C that I am asking for, but the behaviour that the compiler >writers chose to implement in the past and still implement in the >general case. Right, you want to define undefined behavior in a certain why to the exclusion of others. I think that _was_ my entire point. >There is one case where I don't expect consistency: Memory layout >between runs (except as required by the standard). The reason why I >don't expect this is that memory layout also changes often as a result >of software maintenance, or even because of differences in the >environment, so programmers and programs normally don't rely on it to >stay the same across runs. Gosh, this one is actually kinda critical. It enables .dlls and .so and shared libraries and vended binary .o files and loadable kernel modules. These are quite important on some platforms. >One of the problems with the GCC and LLVM maintainers' attitude >towards undefined behaviour is that it is impossible to test whether a >program contains undefined behaviour. So the compilers do have flags that users catch a great many such behaviors. Some are likely practically and/or theoretically impossible to catch due to the the breadth and depth of the language standards. I suspect this inability to catch 100% of the issues, 100% of the time is universal across all C/C++ language systems. It has nothing to do with gcc or llvm. Consider the behavior of *(int *)0x4000. This on one system will produce one value, but on a minor OS update, will produce a different value, and on a different architecture will produce yet another value and so on. It just can't produce the same value across time, across OSes, across compiler versions. It is undefined. No amount of wanting it to be defined matters, it can never be defined (except in exceedingly rare cases). >And even if your flag actually catches all undefined behaviour, the >large majority of programs ("the other 100%", as D.J. Bernstein >writes) will not work as intended with this flag enabled. You presume that most people can't code. I don't know that that is true. I have experience at 3 major OS vendors over 20 years and generally speaking, I've yet to meet anyone that can't code. Maybe I'm lucky. You are the only one that keeps repeating over and over and over that it is impossible to code, that you can't code and that you can't maintain software. I get it, I believe you. My position is that you are the only person I've met that has ever said that. I've done things like build new releases of Apple's entire OS on new compilers and QAed the results. It is not a toy project, nor does it represent just a few programmers. Likewise all the major linux distributors seems able to up port all the software and recompile with newer compilers, year after year. As do ports collections from the major free OS vendors or user communities. Occasionally we do find bugs in programs, and we say, you have to do this and not do this to have your code work, the they do that (or we do that for them) and life goes on. >So you are putting a big workload on the maintainers of all C >programs No, this is an exaggeration. I've rolled in new compiler versions and most code, most of the time survives. About 1 in 400 doesn't, and then that is usually limited to 1-15 issues each. Across projects, there is a tendancy for the same issue to hit over and over again. As time goes by, I suspect these hits dimmish over time, but I don't have 100-200 years of experience and hard data to prove it. I mainly deal with quality OS code, so random .net code could be worse. If you take the time to learn how to program, and simply avoid writting buggy code and maintain your code, over time, you will (likely) become better and your code will have fewer and fewer bugs.