> ----Original Message----
> >From: Joe Buck
> >Sent: 11 July 2005 20:07
> 
> > 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.
> 
>   Indeed so, but I think Sylvester's point is that given that foo takes a
> const pointer, the compiler could theoretically know that foo cannot
> legitimately make any use of (dereference) the pointer value being passed
> and could perhaps issue a warning.

My inital point was a function which gets parameters as pointers
and this pointers have to point to something initalized.
Passing the values gives me the expected warning.
However it's more efficent to refer big data structures
to a function with a pointer.

Now i was looking for a posibility to clearify this the compiler.

I didn't find an adequate attribute.
The use of const was a trial to issue a warning.
I favored an attribute.

cheers,
Sylvester

> 
>   Myself, I was surprised that the inliner didn't catch on to what was going
> on and complain.  I would have expected that, but it didn't even at O3.
> 
>     cheers,
>       DaveK

Reply via email to