[Issue 15488] New: global variable shadows function argument

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Dec 31 02:50:50 PST 2015


https://issues.dlang.org/show_bug.cgi?id=15488

          Issue ID: 15488
           Summary: global variable shadows function argument
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: or at weka.io

abc.d: 

module abc;
int global_x = 0;

main.d:

void foo(int global_x) {
    import std.stdio;
    writefln("Address of func argument: %x", &global_x);
    import abc;
    writefln("Address of func argument: %x", &global_x);
}

void main() {
    foo(5);
}

running:

rdmd main.d

Address of func argument: 7fff56108688
Address of func argument: 7fb0c9c04c70

If I move the import outside of 'foo' the function argument silently shadows
the global variable, which seems fine to me.

--


More information about the Digitalmars-d-bugs mailing list