digitalmars.D - Is there a way to get the size of a class object statically?
- Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> Oct 04 2009
- Lutger <lutger.blijdestijn gmail.com> Oct 05 2009
- Max Samukha <spambox d-coding.com> Oct 05 2009
- "Denis Koroskin" <2korden gmail.com> Oct 05 2009
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? Andrei
This question was on .learn, from where the answer (by Jarret) was: __traits(classInstanceSize, Class)
Oct 05 2009
Lutger wrote: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? Andrei
This question was on .learn, from where the answer (by Jarret) was: __traits(classInstanceSize, Class)
Thanks, Lutger and Max! Andrei
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...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?
sizeof(A) doesn't work?
sizeof(A) doesn't compile. A.sizeof == Object.sizeof == (void*).sizeof
Oct 05 2009









Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> 