What mean "static nested function"?

Kirk McDonald kirklin.mcdonald at gmail.com
Wed Jun 21 12:52:01 PDT 2006


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



More information about the Digitalmars-d-learn mailing list