On 2005-05-30, Christopher <anon@nospam.net> wrote:
[color=blue]
> Well, what happens when somewhere down the line, after the switch, or even
> in a differant case, the value of i is queried? e.g. x = i;[/color]
In the code he posted, i has block scope. So there's no ambiguity -- if that
happens, it's an "undeclared identifier".
[color=blue]
> Unless case 1 is
> guarenteed then there is no such thing as i.[/color]
What about this :
if (flag == 0) {
int i = 0;
} else if ( flag == 1) {
int j = 0;
} else if ( flag == 2) {
int k = 0;
}
if flag is set to 0, then there is no such thing as i either.
[color=blue]
> Because case 1 is the only
> block aware of i's existance at all.[/color]
Likewise above: only the first block knows about i. Yet it is legal.
[color=blue]
> In the second code snipper there is
> always an i. The compiler is smart enough to know this.[/color]
Are you saying that block scope is only allowed if the compiler knows
whether or not that block is executed ?
Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/