Bug 7984 – why is there a hidden field this in nested struct with non-static methods
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-25T00:27:00Z
Last change time
2012-04-25T03:01:02Z
Assigned to
nobody
Creator
thelastmammoth
Comments
Comment #0 by thelastmammoth — 2012-04-25T00:27:20Z
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!
Comment #1 by issues.dlang — 2012-04-25T02:40:00Z
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/
Comment #2 by clugdbug — 2012-04-25T03:01:02Z
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.