what's the scope of a static variable inside a local function?
Steven Schveighoffer
schveiguy at yahoo.com
Fri Jan 5 21:59:38 UTC 2018
On 1/5/18 4:44 PM, Marc wrote:
>> void foo() {
>> void baa() {
>> static int n;
>> writeln(n++);
>> }
>> }
>
>> void main() {
>> static int x;
>> foo();
>> doSomething(x);
>> }
>
> does x and n has same lifetime, i.e, program's execution or n is longer
> available onde foo() call reach out of scope?
>
Both are the same. The lifetime is actually thread-local (one instance
per thread).
-Steve
More information about the Digitalmars-d-learn
mailing list