www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What mean "static nested function"?

reply Thorn <Thorn_member pathlink.com> writes:
Hello, people!

I read docs about nested functions and found this sentence: "Static nested
functions cannot access any stack variables... blah...". What it mean?
Jun 21 2006
parent Kirk McDonald <kirklin.mcdonald gmail.com> writes:
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
Jun 21 2006