Thursday, July 26, 2007

Empty class size c++

People may thinks like the size is zero for an empty class (Me also thought
n the beginning). But it is not true. The size of an empty class will be never
zero. It is nonzero. There are two reasons for that.

1) the sizeof operator in c++ never returns zero.
2) IF the size becomes zero it may cause to have some invalid address
arithmetic operations.

so the size of an empty class is never zero , it is always nonzero (and this
value depends on compiler).

No comments: