www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7984] New: why is there a hidden field this in nested struct with non-static methods

reply d-bugmail puremagic.com writes:
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



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: -------
Apr 25 2012
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Apr 25 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7984


Don <clugdbug yahoo.com.au> changed:

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



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: -------
Apr 25 2012