[Issue 907] New: pointers in static constructors are wack

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 30 07:04:29 PST 2007


http://d.puremagic.com/issues/show_bug.cgi?id=907

           Summary: pointers in static constructors are wack
           Product: D
           Version: 1.004
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: funisher at gmail.com


I get strange things when I try to initialize variables in the static
constructors. It's quite easy to just move the variable outside into the class,
so it's not a severe bug.. also, once the pointer is initialized, it works ok
from then on... here's an example:

import std.stdio;
static class Lala {
        static:
        void delegate() lala2;
        void delegate() lala3;
        void delegate() lala4;
        void delegate() ok2;

        static this() {
                uint* lala;
                uint* ok = null;
                lala2 = delegate() { writefln("inside delegate: should be
'0000': ", lala); lala = new uint; *lala = 5; };
                lala3 = delegate() { writefln("inside delegate: should be
'0000': ", lala, " and the value is: ", *lala); lala = null; };
                lala4 = delegate() { writefln("inside delegate: should be
'0000': ", lala); };
                ok2 = delegate() { writefln("inside delegate: should be '0000':
", ok); };
                writefln("outside delegate: should be '0000': ", lala, " and
'0000': ", ok);
        }
}

void main() {
        Lala.lala2(); // bad
        Lala.lala3(); // behaves as expected
        Lala.lala4(); // behaves as expected
        Lala.ok2(); // bad
}


-- 



More information about the Digitalmars-d-bugs mailing list