
Originally Posted by
larryhaja
The extra compiler flags are in the Makefile(s)/common.mak to keep the code clean. And with the stricter standards that come with newer versions of gcc it shows that (at least for osdep/linux.c) it does not abide by the newer gcc restrictions. It looks like to get it to compile with gcc-4.3 then only linux.c needs to be patched.
The newer warnings shouldn't be thought of as restrictions. Take the following piece of code:
Code:
void Func(int i)
{
if (i = 3)
DoSomething();
else
DoSomethingElse();
}
According to the C language standard, there's nothing at all wrong with this code, it should compile without error. But most compilers will issue a warning, they'll say something like:
Code:
Warning: Assignment in conditional : a.c Line 3 : i = 3 (Did you mean i == 3)?
This is actually a very handy warning because it catches typoes that would otherwise take a while to track down.
But let's say we have different code, something like:
Code:
while ( n = getchar() )
{
DoSomething(n + 5);
}
In this example immediately above, we deliberately want "=" instead of "==", however the compiler doesn't know what we want to do and so it will still issue the same warning. Does this mean there's something wrong with our code? No! It's just a warning, nothing more. Warnings were never meant to be treated as errors. If you have a program that's a few thousand lines long, you might get 20 harmless warnings when you compile it.
Every time you edit your program and re-compile it, you have a read over the warnings to make sure you haven't made a typo of some sort somewhere in the source code. Warnings are to be used by the programmer when he's actually compiling the code to test it out. Warnings are not for use my people who have downloaded source code from the net. In fact, if you are distributing your own source code for other people to compile, you should set a compiler flag to silence all warnings, because the end user doesn't need to know about it.
As for most opensource Linux programs using the "-Werror" flag which treats all warnings as errors, well it's frankly a load of bullshit. Warnings can be produced by perfectly acceptable code, and as we've seen with MDK3, new errors are added to compilers all the time to help programmers catch their mistakes faster. As more and more warnings are added to a compiler, then code is eventually gonna break if it specifies "-Werror".
The people who are distributing opensource Linux programs must all be using the same makefile producing program, because all the makefiles are the same, they're all broken in the same way. I myself don't use makefiles at all, I just give GCC everything it needs at the command line, for example here's how I compile my Internet Prober program:
Code:
gcc *.c -g -D inline="static inline" -D _REENTRANT -D VJC_PLATFORM=1 -D NO_ERRPRINT -lpthread -lncurses -o inp
If you want to change your source code so that it doesn't produce any warnings, then there are ways of doing so. For instance, for the "Assignment within a conditional" warning, you can suppress it in GCC by using two pairs of parentheses:
Code:
while (( n = getchar() ))
{
Whatever();
}
One of the warnings produced by the MDK3 code is that a particular function should never have its return value discarded. So instead of having:
You need something like:
Code:
int i = SomeFunction();
There was one other warning I believe, something to do with string literals, but I never bothered to investigate it.
I wouldn't go patching files like linux.c just to make them past a warning test. If you really want warnings to disappear, you can specify all sorts of flags to GCC:
Warning Options - Using the GNU Compiler Collection (GCC)
I can't stress enough though: Warning should never be treated as errors, not even when the programmer is testing out his code. To have warnings treated as errors in the makefile of source code which is distributed to the public, is nonsense. If every program was distributed like this, they'd all be broken within 5 years.
When I'm testing my own programs, I tend to use "-Wall", it tells the compiler to give me every warning possible, no matter how ridiculous the warning is. However you'd never see me include this a compiler flag when I'm telling other people to compiler my code.