June 21, 2006 What mean "static nested function"? | ||||
---|---|---|---|---|
| ||||
Hello, people! I read docs about nested functions and found this sentence: "Static nested functions cannot access any stack variables... blah...". What it mean? |
June 21, 2006 Re: What mean "static nested function"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thorn | Thorn wrote:
> Hello, people!
>
> I read docs about nested functions and found this sentence: "Static nested
> functions cannot access any stack variables... blah...". What it mean?
>
>
"Stack variable" is another way of saying "local variable," e.g.:
int foo(int a) {
int i; // This is a stack variable.
static int bar(int b) {
return b + i; // ERROR! bar is static!
}
return bar(a);
}
If bar weren't declared static, then that example would work (it would be able to access foo's stack). As it is, it shouldn't compile.
-Kirk McDonald
|
Copyright © 1999-2021 by the D Language Foundation