www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7765] New: Cannot access __gshared function pointers from static methods

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7765

           Summary: Cannot access __gshared function pointers from static
                    methods
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



18:32:23 PDT ---
class Foo
{
    static int test()
    {
        return c_func();
    }

    extern(C) __gshared int c_func();
}

test.d(7): Error: need 'this' to access member c_func

The docs say:
__gshared may also be applied to member variables and local variables. In these
cases, **__gshared is equivalent to static**, except that the variable is
shared by all threads rather than being thread local.

And true enough it works fine with regular variables:
class Foo
{
    static int getX() { return x; }
    extern(C) __gshared int x;
}

But not with function pointers, unless they're declared outside the class. I
think this is a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 24 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7765




09:41:02 PDT ---

 c_func() is a function, not a function pointer nor a variable, and so __gshared
 has no effect on it.
 
 Not a bug.
Ok. But why is 'static' required? This won't work: class Foo { static int test() { return c_func(); } extern(C) int c_func(); } test.d(5): Error: need 'this' to access member c_func -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 06 2012