This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch for various warnings in gcc
- From: Dale Johannesen <dalej at apple dot com>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: Dale Johannesen <dalej at apple dot com>, Michael Matz <matz at suse dot de>, "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 8 Aug 2002 10:54:23 -0700
- Subject: Re: Patch for various warnings in gcc
On Thursday, August 8, 2002, at 10:32 AM, Zack Weinberg wrote:
On Thu, Aug 08, 2002 at 12:05:05PM +0200, Michael Matz wrote:
ra-build.c:1818: warning: `web' might be used uninitialized in this
function
This warning is wrong, as web in fact is initialized in all possible
paths. There is no need for a fix, except maybe to silence the warning.
Wasn't there a gcc extension ala "int a = a;" to silence it?
This topic has come up in the past; the consensus was that when GCC
couldn't prove a variable initialized, it was best to initialize it
at declaration to a value that would cause an immediate failure if
used. (NULL, for pointers.) The cost of doing a single
load-constant-zero instruction is unlikely to be measurable, and using
a deterministic initializer is simply good defensive programming. We
have unconditional 'if (impossible) abort()' checks all over the
compiler - those are more expensive, surely, and no one suggests
removing them.
Well, there's a difference between checks that affect only the compiler
itself and generating extra code in user programs. Still, I'd expect
the optimizer to get rid of the dead store in most cases where it mattered,
so I don't have a problem with this.
Personally I agree with Dale that 'int a = a;' is too obscure a way of
silencing this warning. If we must have a way to disable it without
generating extra code, let us create __attribute__ ((initialized))
which states explicitly what is going on.
I like this.