C
Champika Nirosh
Agreed, no argument
Can you just read the link I gave and made your comments?
Nirosh.
Okay, I think it's time to start looking at what the spec has to say.
ECMA numbering used throughout.
From section 12.1.7:
<quote>
The lifetime of a local variable is the portion of program execution
during which storage is guaranteed to be reserved for it. This lifetime
extends from entry into the block, for-statement, switch-statement, or
using-statement with which it is associated, until execution of that
block, for-statement, switch-statement, or using-statement ends in any
way.
</quote>
So no, not the whole method - just the block it's associated with.
Also from 12.1.7:
<quote>
Within the scope of a local variable, it is a compile-time error to
refer to that local variable in a textual position that precedes its
local-variable-declarator.
</quote>
That addresses your other question about why you can't do
i=1;
int i;
From section 10.7:
<quote>
The scope of a local variable declared in a local-variable-declaration
(§15.5.1) is the block in which the declaration occurs.
The scope of a local variable declared in a switch-block of a switch
statement (§15.7.2) is the switch-block.
The scope of a local variable declared in a for-initializer of a for
statement (§15.8.3) is the for-initializer, the for-condition, the for-
iterator, and the contained statement of the for statement.
</quote>
Can you just read the link I gave and made your comments?
Nirosh.
Champika Nirosh said:What proof you have to say that the the variable (which define in a block)
lifetime is not equal to that of the entire procedure.
your example is not capable of talking about the life time and I am not
talking about the SCOPE.
Okay, I think it's time to start looking at what the spec has to say.
ECMA numbering used throughout.
From section 12.1.7:
<quote>
The lifetime of a local variable is the portion of program execution
during which storage is guaranteed to be reserved for it. This lifetime
extends from entry into the block, for-statement, switch-statement, or
using-statement with which it is associated, until execution of that
block, for-statement, switch-statement, or using-statement ends in any
way.
</quote>
So no, not the whole method - just the block it's associated with.
Also from 12.1.7:
<quote>
Within the scope of a local variable, it is a compile-time error to
refer to that local variable in a textual position that precedes its
local-variable-declarator.
</quote>
That addresses your other question about why you can't do
i=1;
int i;
From section 10.7:
<quote>
The scope of a local variable declared in a local-variable-declaration
(§15.5.1) is the block in which the declaration occurs.
The scope of a local variable declared in a switch-block of a switch
statement (§15.7.2) is the switch-block.
The scope of a local variable declared in a for-initializer of a for
statement (§15.8.3) is the for-initializer, the for-condition, the for-
iterator, and the contained statement of the for statement.
</quote>