www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - .sizeof for classes

How to get the size of an object?

class Test
{
	uint[10] a;
}

void main()
{
	Test t = new Test;

	assert( Test.sizeof == 4 );
	assert( t.sizeof == 4 );
	assert( Test.classinfo.init.length == 48 );

}

static assert( Test.classinfo.init.length == 48 ); // is not evaluatable
at compile time.


Isn't this syntax weird?
How can I get the size at compile time?
Mar 27 2006