Eigenpoll : D wish list : Consistent struct/class sizeof 

The sizeof property for primitive types and structures returns the number of bytes required for the entity. Sizeof for classes though (which are simply heavyweight structures) returns the size of the pointer to it, not the expected and desired number of bytes needed for the class. Regardless of any potential arguments about needing the size of a pointer for when passing variable arguments, it's clearly not what anyone logically expects from this property :-/

If there is a real need for a property to return the size of a pointer instead (which can be obtained with just null.sizeof), then an additional property should be added, leaving .sizeof to mean the bytes needed for the actual entity. That way, the use of either a struct or a class would be transparent and interchangeable. Currently, the only hack I know of is the following (and we all know the beauty of the new language is ridding the old C/++ hacks):

class SomeClass {
public:
int var1, var2, var3;

int byteSize()
{
return
var3.offsetof + var3.sizeof;
}
}


Report this item for cleanup