lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wednesday 05 October 2005 04:26, Chris Marrin wrote:
[...]
> Not to mean any disrespect to the great designers of Lua, but the
> designers of C certainly thought about this long and hard and made the
> decision to keep it out of the inner scope, probably for exactly this
> reason. So following that wisdom might be a good choice.

As another data point:

C++ (and now C99) allows you to declare loop variables inside loop statements:

for (int i=0; i<10; i++)
{
	printf("%d\n", i);
}

It's interesting to note that old versions of the standard decreed that the 
scope of the loop variable extended until the end of the enclosing scope; 
that is, it was equivalent to:

int i;
for (i=0; i<10; i++)
	...

However, the standard then changed so that the scope was limited to the for() 
block only.

I've been trying to track down the reasons why they changed their minds over 
this, because their reasoning might be informative... but I can't. But they 
obviously thought it was important enough to actually make an incompatible 
change to the standard.

(Look for -ffor-scope and -fno-for-scope in gcc.)

-- 
+- David Given --McQ-+ 
|  dg@cowlark.com    | Wholesale theft is the sincerest form of flattery.
| (dg@tao-group.com) | 
+- www.cowlark.com --+ 

Attachment: pgpX2AurYzXVN.pgp
Description: PGP signature