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

--- Comment #0 from 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?

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.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to