Class Field Size/Offsets

Maxime Chevalier maximechevalierb at gmail.com
Sat Mar 2 13:30:57 PST 2013


To access class fields in machine code generated by my JIT 
compiler, I need to be able to know the offset and size of the 
said fields. It seems that D requires a pointer to an instance of 
the class to make this work. This seems rather problematic for my 
usage.

Is it safe to circumvent this by using a null pointer or could I 
potentially get an exception/segfault by doing this? E.g.:

MyClass ptr = null;

auto fSize = ptr.theField.sizeof;
auto fOffs = ptr.theField.offsetof;

Is it safe to assume that the offset is the same in every 
instance? I would assume so (why would the offsets change?) but 
I'd like to know if the language actually guarantees this.


More information about the Digitalmars-d mailing list