Flash Gordon said:
Rainer said:
Keith Thompson said:
On Feb 19, 8:51 pm, The Lost Packet <
[email protected]>
wrote:
[...]
gcc is more forgiving of untidy code, hence you
will get generally more functional results using it wihtout having to
drastically rewrite your source.
That's great for people who want "generally more functional results".
But I want *reliable* results.
Is the warning insufficient for that purpose?
gcc does have a number of options that cause it to produce more
diagnostics, and one that turns warnings into errors. (The latter can
be a problem if gcc warns about something that you don't consider to
be serious.)
gcc warns about perfectly valid C, eg comparing the values of signed
and unsigned integers or use of && and || for flow-control.
If you don't like some of the warnings a given compiler produces read
the manuals and find out how to disable those warnings. There is no
guarantee you can disable them of course, but with gcc you generally
can.
I've already encountered people who simply use gcc -Wall -W -Werror
and then go shopping for all kinds of weird hacks to smuggle correct
code past the compiler (and had to modify build systems for the same
reason). The point was supposed to be that the 'default selections'
for gcc-warnings are not really suitable for treating warnings as
errors, because generally[*], they are intended to rather complain
about something which is ok than to let something slip which might be
not (which I consider to be a sensible policy in this respect).
[*] The exception is that -Wpointer-arith needs to be enabled
if one wants to get a warning when the compiler encounters
arithmetic operations on void *s (which is usually a
'higher-order typo' in code I write).
Whether the warning being spurious or not is normal will very much
depend on the type of code you are writing and how you write
it. Personally I've seen it be correct (or the code complex enough for
a human to have problems proving the the variable is guaranteed to be
initialised, more often than I've seen it be wrong.
In my experience, it has been almost always wrong, the usual reason
being that no sensible default value for some variable exists and
because of this, a value is assigned to it based on 'some condition',
eg, in a switch-case, and it is then later-on used conditionally, with
some code common to all cases in between. And blindly writing a
nonsensical value into the variable in order to get rid of the
warning, as some people occasionally advocate, is something I consider
to be a decidedly bad idea: At best, this accomplishes nothing and at
worst, it causes exactly the same problem that an uninitialized
variable would have caused, too. Code which doesn't work because of
logic errors isn't really an improvement over code which doesn't work
because of using unpredictable values, even the despite the former
being conformant to the letter of the C-standard.