digitalmars.D - Is there a way to get the size of a class object statically?
- Andrei Alexandrescu (15/15) Oct 04 2009 I figured out a way to get the offsetof any member statically:
- Lutger (3/25) Oct 05 2009 This question was on .learn, from where the answer (by Jarret) was:
- Andrei Alexandrescu (3/32) Oct 05 2009 Thanks, Lutger and Max!
- Max Samukha (3/18) Oct 05 2009 __traits(classInstanceSize, A)
- Denis Koroskin (3/26) Oct 05 2009 sizeof(A) doesn't compile.
I figured out a way to get the offsetof any member statically: class A { char a; int b; char c; } void main() { int[A.init.a.offsetof] x; } Unfortunately, I can't figure a way to get the class' size statically. This doesn't work: int[A.classinfo.init.length] x; Any way to fetch the size of A? Andrei
Oct 04 2009
Andrei Alexandrescu wrote:I figured out a way to get the offsetof any member statically: class A { char a; int b; char c; } void main() { int[A.init.a.offsetof] x; } Unfortunately, I can't figure a way to get the class' size statically. This doesn't work: int[A.classinfo.init.length] x; Any way to fetch the size of A? AndreiThis question was on .learn, from where the answer (by Jarret) was: __traits(classInstanceSize, Class)
Oct 05 2009
Lutger wrote:Andrei Alexandrescu wrote:Thanks, Lutger and Max! AndreiI figured out a way to get the offsetof any member statically: class A { char a; int b; char c; } void main() { int[A.init.a.offsetof] x; } Unfortunately, I can't figure a way to get the class' size statically. This doesn't work: int[A.classinfo.init.length] x; Any way to fetch the size of A? AndreiThis question was on .learn, from where the answer (by Jarret) was: __traits(classInstanceSize, Class)
Oct 05 2009
On Mon, 05 Oct 2009 01:47:21 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:I figured out a way to get the offsetof any member statically: class A { char a; int b; char c; } void main() { int[A.init.a.offsetof] x; } Unfortunately, I can't figure a way to get the class' size statically. This doesn't work: int[A.classinfo.init.length] x; Any way to fetch the size of A? Andrei__traits(classInstanceSize, A)
Oct 05 2009
On Mon, 05 Oct 2009 14:13:06 +0400, Nick Sabalausky <a a.a> wrote:"Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message news:hac4pl$1s2e$1 digitalmars.com...sizeof(A) doesn't compile. A.sizeof == Object.sizeof == (void*).sizeofI figured out a way to get the offsetof any member statically: class A { char a; int b; char c; } void main() { int[A.init.a.offsetof] x; } Unfortunately, I can't figure a way to get the class' size statically. This doesn't work: int[A.classinfo.init.length] x; Any way to fetch the size of A?sizeof(A) doesn't work?
Oct 05 2009