Subject: Re: bool and gcc
From: [email-masked] (Theodore Jump)

11 Aug 1998 20:37:16 -0700
Message-ID: <35d074eb.11390015.cygnus.gnu-win32@smtp>
References: <[email-masked]>
Reply-To: [email-masked]
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: [email-masked]

>> .cc:120: warning: name lookup of `index' changed for new ANSI `for'
>scoping
>> .cc:119: warning:   using obsolete binding at `index'
>> 
>> What's that "new ANSI 'for' scoping" ?
>
>ANSI C++ had a late change regarding the scoping rules for variables
>declared as part of a "for" statement. I forget the specific details; I
>remember reading an article in C/C++ Users Journal which discussed it.

In short, variables declared inside the parens of a for() loop are scoped to
the block ENCLOSING the for loop, NOT to the for loop's code block.  Example:

	void foofun(void)
	{
		for (int i=0; i<10; i++)
		{
		}
	}

	In the above, the "int i" is scoped to the entirety of foofun(), but
	is only available for use after it's declaration in the for() loop. Any
	code added prior to the for loop will now "know" about 'i'.

The problem with this, wrt:legacy code, is a sequence like this:

	void foofun(void)
	{
		for (int i=0; i<10; i++)
		{
		}

		// another loop doing something else

		for (int i=0; i<10; i++)
		{
		}
	}

	In the above, it would compile and work as expected on ANSI C and
	"not quite Standard C++" compilers, however in a "Standards Compliant"
	C++ compiler it should cause some kind of compiler error as two variables
	have been declared of the same name in the same scope.  This is equivalent
	to doing the following:

	void foofun(void)
	{
		int i;
		int i;

		for (i=0; i<10; i++)
		{
		}

		// another loop doing something else

		for (i=0; i<10; i++)
		{
		}
	}

	Which is obviously just plain wrong code.

	Why the committee did this? Dunno. I'm sure they have their reasons, but
	it's surely going to "break" a lot of code.

Regards,
-Ted
______________________________________________________________________
http://www.i21.com/~tjump                  http://www.fighterduel.com
----------------------------------------------------------------------
Congrats to Marco Pantani, Jan Ullrich, Bobby Julich, Erik Zabel,
Christophe Rinero and all the rest of the riders of Le Tour '98!
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".