On Fri, Apr 25, 2014 at 04:42:09PM +0200, Roberto E. Vargas Caballero wrote: > The problem is Wall change from one system to another (this is something > OpenBSD users know with strcpy calls...), and it doesn't force how to > remove the warning, so at the end I think style is not really improved > with Wall (and guys, some of the warning are really, really stupid). >
That's one of the problems with C and gcc: Too many messages fall into the same category of "warning". gcc warns you about a comparison between signed and unsigned variables even in places where that can't bite you, like in int s; unsigned u; /* ... */ if (s < 0 || s < u) In this case the "s < u" is only evaluated if s's value is representable in unsigned. gcc will warn anyway. At the same time "implicit declaration of function X" is just a warning, too. And it can crash your program not to declare a function. If a function is supposed to return a pointer, and you don't declare it at the call site, even if you cast the result to remove the "assignment makes pointer from integer without cast" warning, and you are on x86-64, and the pointer returned is bigger than INT_MAX (e.g. on the stack), then the result's top 32 bits will get ignored, the lower 32 bits will get a sign extension and your program will segfault while trying to access kernel space. Which is very annoying when the program in question is "login", which you yourself bothed the day before. This may have happened to me. And then there are the bizarre cases, like "variable X may not be initialized": That is an incredibly helpful warning that is only produced when gcc is optimizing (I guess it's a byproduct of the flow analysis, which is part of the optimizer). However, when developing I usually have the optimizer off so I can debug. And this warning is removed in newer versions of gcc entirely. But not the command line option for it. Nice! I'm switching to clang! > I moved to Linux kernel style some years ago, but I am beginning to break > some rules, basically the typedef rule. I accept typedef of struct always > that the new type begins with upper case. > I never typedef my structs. At least for private works. Professionally I have to abide by the company rules (which are the kind of pussy-footing rules you'd expect from a bunch of engineers trying to do programming, like "don't use the ternary operator, it's hard to understand" or "don't return from anywhere but the final statement of a function" that are supposed to make the source code easier to read but completely miss that they still allow 100-line structs and 3000-line functions), but in private I think C desperately needs namespaces so I'm not going to destroy the only namespaces C has. Sorry this became quite a rant and a lot off topic. Ciao, Markus