On Sat, 31 May 2014 16:18:33 +
DLearner via Digitalmars-d-learn digitalmars-d-learn@puremagic.com
wrote:
Hi,
import std.stdio;
void main() {
writefln(Entered);
sub1();
sub1();
sub1();
writefln(Returning);
void sub1() {
static int i2 = 6;
Hi,
import std.stdio;
void main() {
writefln(Entered);
sub1();
sub1();
sub1();
writefln(Returning);
void sub1() {
static int i2 = 6;
i2 = i2 + 1;
writefln(%s,i2);
};
}
does not compile, but
import std.stdio;
void main() {
void sub1() {
On Saturday, 31 May 2014 at 16:18:35 UTC, DLearner wrote:
Is this intended?
Yes, nested functions access local variables and thus follow the
same order of declaration rules as they do; you can't use a local
variable before it is declared so same with a nested function.
See: http://dlang.org/function.html#variadicnested
The second example explains that nested functions can be accessed only
if the name is in scope.