News for hackers. Stuff that matters.
Re:Useful GCC warning options not enabled by -Wall -Wextra by jlg23 on Wednesday October 04, 2017 @02:58PM (#15403345)
I disagree. Rather write nasty rants in comments that explain compiler-specific workarounds. It should not be too many anyway, if one adheres to KISS.

Otherwise you surrender control over the correctness of your program "to the whims of the same people who think that it's okay that memcpy(0, 0, 0) is undefined behavior".

More debatable decisions will be made in compiler implementations and I'd rather force the user who compiles the program to understand the implications of warnings by turning them into errors than letting them ignore them (because "it compiled, after all!").

If I was to make the call, I'd make "-Werror" default in all compilers, remove the option and allow to disable it by "--I-really-want-to-ignore-warnings-for-fscks-sake" which when used would sleep(30) after an all-caps nag screen that tells people "don't ever use that option."

Re:Useful GCC warning options not enabled by -Wall -Wextra by spc476 on Wednesday October 04, 2017 @05:06PM (#15404657)
I have one project where I run with "-pedantic -std=c99 -Wall -Wextra". The one error that pops up is:

     warning: ISO C forbids assignment between function pointer and ‘void *’ [-pedantic]
But POSIX requires that behavior (the actual target of the build). So for now, it's benign, but if the platform changes (to a non-POSIX system) then yes, it will have to be investigated.
Re:Useful GCC warning options not enabled by -Wall -Wextra by nwellnhof on Thursday October 05, 2017 @07:43AM (#15408334)
This affects many codebases. For example, looking up functions with `dlsym` triggers this warning which is probably one of the main reasons for the POSIX requirement. It's unfortunate that GCC doesn't allow to disable only this particular warning. When writing cross-platform code, `-pedantic` is too useful to disable completely.
Re:Useful GCC warning options not enabled by -Wall -Wextra by daurnimator on Thursday October 05, 2017 @04:23AM (#15407463)
Try using intptr_t
Re:Useful GCC warning options not enabled by -Wall -Wextra by millstone on Wednesday October 04, 2017 @03:23PM (#15403628)
When I download some random unmaintained tarball from years back, I don't want to have to fight with the compiler. Just build dammit.
Re:Useful GCC warning options not enabled by -Wall -Wextra by anyfoo on Wednesday October 04, 2017 @03:54PM (#15403933)
"When I buy some random unmaintained car from years back, I don't want to have to fight with the transmission fault mode. Just drive dammit."
Re:Useful GCC warning options not enabled by -Wall -Wextra by dottedmag on Thursday October 05, 2017 @04:03AM (#15407369)
The better analogy is: "When I pick up some blueprint for the building from 80s I don't want to have to fight with changed sensibilities of the foreman. Just build the thing dammit."
Re:Useful GCC warning options not enabled by -Wall -Wextra by throwaway2048 on Wednesday October 04, 2017 @04:30PM (#15404320)
Software doesn't mechanically wear over time, this is an awful analogy.
Re:Useful GCC warning options not enabled by -Wall -Wextra by anyfoo on Wednesday October 04, 2017 @04:46PM (#15404467)
Yeah, I admit. A better analogy on my part would have been that you buy a car and it's not street legal anymore, or one that does not work in today's environment anymore. "I don't want to add seat belts, just drive" or "I don't want it to run on unleaded fuel". (Note that I have no idea if there actually were cars that required leaded fuel.)

Anyway, I think even more likely than running into new compiler warnings/errors is running into external dependency issues, which require you to touch the software anyway, and, I'd argue, are often much harder to fix than fixing code that triggers warnings.

Re:Useful GCC warning options not enabled by -Wall -Wextra by AgentME on Wednesday October 04, 2017 @04:41PM (#15404423)
If you build old software that relied on a specific compiler treating undefined behavior in a certain way, then it could.
Re:Useful GCC warning options not enabled by -Wall -Wextra by jcelerier on Wednesday October 04, 2017 @04:53PM (#15404536)
yes, people actively rewrite it in rust instead

More seriously, software certainly wears, not relative to itself but relative to the environment it is run in. It wears in the sense that active maintenance operations are needed to have old software perform as it should: installing old libraries, running it in emulators, etc.

Re:Useful GCC warning options not enabled by -Wall -Wextra by Arkanosis on Wednesday October 04, 2017 @04:38PM (#15404389)
You'd be surprised…
Re:Useful GCC warning options not enabled by -Wall -Wextra by digi_owl on Wednesday October 04, 2017 @04:44PM (#15404446)
What are the odds that a tar-ball suffering bitrot will decompress cleanly?
Re:Useful GCC warning options not enabled by -Wall -Wextra by Arkanosis on Wednesday October 04, 2017 @05:02PM (#15404626)
What I had in mind was UB changing over time more than tarballs getting corrupted (eg. strict aliasing-related optimizations).

There's practically no chance for a corrupted gzip-compressed tarball to decompress cleanly (even if by chance it inflates without error, there's a CRC32 of the uncompressed payload at the end of the gzip stream).

Re:Useful GCC warning options not enabled by -Wall -Wextra by kbenson on Wednesday October 04, 2017 @05:28PM (#15404862)
> What I had in mind was UB changing over time

I don't want to keep posting this[1] in every C discussion, but when it's relevant, it's relevant. TL;DR A particular version of a compiler interpreted undefined behavior in such a way as to elide code that specifically tested for an error case to exit early because the error implied undefined behavior, so the test could never be reached without undefined behavior. If that sounds like circular logic, that's because it is.

The error happened to exist in a fairly specific version of clang shipped by apple, but not in any of the major release versions:

I was not able to reproduce this bug on other platforms, perhaps because the compiler optimization is not applied by other compilers. On Linux, I tested GCC 4.9, 5.4, and 6.3, as well as Clang 3.6, 3.8, and 4.0. None were affected. Nevertheless, the compiler behavior is technically allowed, thus it should be assumed that it can happen on other platforms as well.

The specific compiler version which was observed to be affected is:

$ clang++ --version

Apple LLVM version 8.1.0 (clang-802.0.41)

Target: x86_64-apple-darwin16.5.0

Thread model: posix

InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

(Note: Despite being Clang-based, Apple's compiler version numbers have no apparent relationship to Clang version numbers.)

1: https://news.ycombinator.com/item?id=14163111