3 ms·
>> Sure there are a handful of good companies that enable every single compiler warning. You think so? Every company I've worked for, or that I've known people
by w0utert 10y ago
>> Sure there are a handful of good companies that enable every single compiler warning.
You think so? Every company I've worked for, or that I've known people that worked there, always enabled -Wall for their C and C++ code. Most OSS software compiles with all warnings enabled.
I think the issue with undefined behavior in C/C++ is extremely overblown, aside from fun academic examples like 'what does i++++i++ evaluate to' there isn't actually all that much undefined behavior or gotchas in C/C++. I would say there are less, compared to other languages I know.
- rwmj 10y agoSigned overflow problems are everywhere, even in carefully written code. Using 'int' instead of a more specific type is a code smell. Security code which presumes that because you wrote ptr != NULL, that the check is actually carried out. Code that does type punning. Code that doesn't know about aliasing. It goes on and on. You need to know that the problem exists in order to know that you have a problem. There are many C programmers who learned C back in the 1980s who don't even realize these are issues.
- tarancato 10y agoI'd say things have changed quite a bit since format string bugs...
- MaulingMonkey 10y agoSince? I'm still adding the compiler specific annotations to add format string checking to custom variadic logging functions in codebases I inherit, and finding multiple bugs.
- majewsky 10y ago> always enabled -Wall for their C and C++ code Of course you want -Wall -Wextra -Werror -pedantic. ;)
- mitchty 10y agoOr if you don't have to use gcc, just -Weverything in clang.
- david-given 10y ago...but please, for the love of Mike, don't ship source code with -Werror. There's nothing like the experience of trying to fix somebody else's code which compiled fine on gcc version 8.97 but which now fails to compile on gcc version 8.98 because the new compiler has some new warnings, which it's now treating as errors, and now fails to compile. ...and you've got stuff to do, and the program isn't even broken.
- wtbob 10y ago> … and you've got stuff to do, and the program isn't even broken. Well, it may be — that's one of the problems with C: you never really know for sure if a warning really matters or not. But man, there sure are a lot of them!
- GFK_of_xmaspast 10y agoI used to work with a guy who would regularly get upset about the idea letting the compiler return warnings because he knew better and didn't want to be bothered with it. Last I checked he has a couple hundred points on the hacker news internet forums. Also just last week I found and reported some undefined behavior in a major c++ package that's used by almost every player in as many as several industries. I don't expect it will ever make any difference in production, but it still snuck in.