This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: attribute initialized
- From: Joe Buck <Joe dot Buck at synopsys dot COM>
- To: Sylvester Diehl <diehl at dachau dot marco dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 11 Jul 2005 12:06:37 -0700
- Subject: Re: attribute initialized
- References: <m1Ds2ga-007uQcC@hera.dachau.marco.de>
On Mon, Jul 11, 2005 at 08:07:20PM +0200, Sylvester Diehl wrote:
> why doesn't gcc (-Wall -Wuninitalized -O) detect
> an uninialized variable passed by reference
> decleared as <type> const *<name> ?
There are no uninitialized variables in your program. For the
kind of access checking you seem to be asking for, you'll need
something like valgrind or mudflap.
> int foo(int const *p)
> {
> static int sum = 0;
>
> sum += *p;
> return sum;
> }
it happens that the memory that p points to is unitialized, but
that is not what -Wuninitialized does. Similarly, in
> int main(int argc, char **argv)
> {
> int k;
>
> return printf("%d\n", foo(&k));
> }
there are no uninitialized variables, as the address of k is
perfectly well defined.
> p.s. i know i could pass the variable by value
> to get a warning of an uninitalized variable.
Yes, because then there will *be* an unitialized variable.