7 ms·
> The personal opinions of future compiler authors shouldn't affect whether your program builds successfully. So, let's say that you find some 2003 software o
by jcelerier 9y ago
> The personal opinions of future compiler authors shouldn't affect whether your program builds successfully.
So, let's say that you find some 2003 software on some deep corner of SourceForge that you want to use.
Would you rather :
* Have the build fail because new warnings were introduced ?
* Have the build succeed and then get crashes at runtime because the behaviour of the compiler changed anyways and the program was rendered invalid ?
I'll personally always want the first one.
- quotemstr 9y agoThere's a name for a kind of change that makes a previously correct program incorrect: "compiler bug".
- jcelerier 9y ago> There's a name for a kind of change that makes a previously correct program incorrect: "compiler bug". No. The only thing that matters is that the language rules are respected. Or maybe you'd want programs that were correct with the first C compilers to still work today ? Because for instance they didn't do type checks at all. `void f(float, float); int x = f;` you say ? no problem! `char c; c[-15];` ? no problem! Everything did compile, sure. Is it the world we want ? Most certainly not.
- colejohnson66 9y agoTrigraphs used to be part of the standard and are now removed. So really old programs that used them now would fail to compile. Granted, that is a bit of a low hanging fruit.
- mrguyorama 9y agothe program wasn't "previously correct", else a new, but still language compliant, compiler would build it just fine
- YSFEJ4SWJUVU6 9y agoWorth noting that some warning flags (at least when combined with -Werror* ) make the compiler not standard compliant. * It's been some time since I last partook in language lawyering, and can't remember if standard compliant C compilers are allowed to produce diagnostics, the term used, for well-defined code as long as they also succeed.
- mrguyorama 9y agoDo you have an example I could take a look at? I'm actually not well versed in the C world
- YSFEJ4SWJUVU6 9y agoUnintended code (like having both arms of an if-else-statement execute the same action, or a duplicate condition in a logical expression) is sometimes perfectly valid as far as the standard goes. A double condition for example may simply be a result of poor refactoring, and thus the program even works as intended – however, the compiler cannot know that. That's why the helpful warnings flag those statements – -Werror then makes the compiler abort the compilation altogether on any warnings which is clearly not standard-compliant in cases like the one I outlined. The majority of the warning options showed in the article are intended to find unintended code (which can however perfectly defined if not intended behaviour as opposed to invalid, undefined behaviour). The very basic examples showed for those options also themselves do not contain anything that by itself would make the code not standard-compliant.
- dkersten 9y agoWell, the standard does not say that if you ask the compiler to flag potentially suspect code that it should compile successfully. That doesn’t make it non standard if you decide you do want your compiler to stop compiling when it encounters potentially suspect code and enable that mode wth a conpiler flag.
- microtherion 9y ago
- eru 9y agoWho says the program was previously correct? Just because it compiled and didn't blow up so far, doesn't mean it's correct. It might or might not have been correct..
- spc476 9y agoAlso "horribly written code." I've been playing around with some code from 1993---the Viola web browser (one of the first graphical web browsers). Ooh boy was it fun when I ran it with "-pedantic -Wall -Wextra". Hundreds, if not thousands of warnings. A ton of unused argumetns, implicit declarations (no prototypes), unused variables, return type not specified, a few "control reaches end of non-void function," some format string mismatches. Pretty much what you would expect from K&R C (the code paid some lip service to ANSI C, but not a whole lot). Also, the code runs (not well, but it does) on 32-bit systems, but immediately crashes on a 64-bit system. That's because of the whole "int==long==ptr==32 bits" that permeates the code.