Thread overview
[Issue 7984] New: why is there a hidden field this in nested struct with non-static methods
Apr 25, 2012
Jonathan M Davis
Apr 25, 2012
Don
April 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7984

           Summary: why is there a hidden field this in nested struct with
                    non-static methods
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: thelastmammoth@gmail.com


--- Comment #0 from thelastmammoth@gmail.com 2012-04-25 00:27:20 PDT ---
Why is there a hidden field "this" in a struct with non-static methods that is defined in a function?

given:
void myfunction(){
   struct C1{int n; }
   struct C2{int n; void fun(){}}
   writeln(C1.init); //prints C(0)
   writeln(C1.init.sizeof); //prints 4
   writeln(C2.init); //prints C(0,null)
   writeln(C2.init.sizeof); //prints 8 (on 32bit)
}

In visualD, C2 appears as {n=0 this=0x00000000 }. this only occurs when C2 has at least 1 non-static method.

* Why is this, since C2 seems to be a POD ?
* the "this" field seems to be always 0x00000000 (from inspection in visualD)
* the hidden extra field (and extra size) disappears when C2 is not defined
inside a function, or is defined in a class.


I couldn't find any related info in the book nor the docs. Thanks!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7984


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg@gmx.com
         Resolution|                            |INVALID


--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-04-25 02:40:00 PDT ---
Why are you asking a question in a bug report? Bugzilla is for bug reports and enhancement requests, not questions. Please ask questions in the newsgroup:

http://forum.dlang.org/

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7984


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-04-25 03:01:02 PDT ---
There may be a valid spec bug here: the 'structs and unions' page says that a struct is a POD, but it's not true in the case of nested structs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------