This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: shadowed "for" scope variables not throwing up a warning (gcc 3.1.1/cygwin)
- From: Fergus Henderson <fjh at cs dot mu dot OZ dot AU>
- To: Dylan Cuthbert <dylan at q-games dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 6 Aug 2002 00:10:33 +1000
- Subject: Re: shadowed "for" scope variables not throwing up a warning (gcc 3.1.1/cygwin)
- References: <ailm58$bkr$1@main.gmane.org>
That's what `-Wshadow' is for.
Were you compiling with `-Wshadow' enabled?
On 05-Aug-2002, Dylan Cuthbert <dylan@q-games.com> wrote:
>
> for ( int i = 0; i < 10; i++ )
> {
> int i = 10; <===== shadowing the i variable
> printf( "%d\n", i );
> }
>
>
> To my understanding, the "int i" in the for statement is within the scope of
> the following curly brackets?
>
> If this isn't an error (ie. there is a special "mini" scope created around
> the for statement's scope), then it *definitely* *definitely* (pretty
> please) should throw up a warning. I just spent a while looking at some
> code before realising it was something as silly as this.
>
> Regards
>
> ---------------------------------
> Q-Games, Dylan Cuthbert.
> http://www.q-games.com
> P2P internet radio - http://www.peercast.org
>
>
>
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.