sizeof empty class

leon zadorin leonleon77@gmail.com
Fri Apr 9 03:38:00 GMT 2010


My understanding is that sizeof empty class/struct in C++ is defined
to never be 0 (every object must be addressable, e.g. in cases like
arrays and pointer arithmetic etc. etc.): "no object shall have the
same address in memory as any other variable"

in C(99) standard however, I am under impression but could be wrong,
the sizeof empty struct is undefined (i.e. could be 0):
C99: "If the struct-declaration-list contains no named members, the
behavior is undefined."

anyway -- just my 2 cents.

leon.

On 4/8/10, ranjith kumar <ranjithproxy@gmail.com> wrote:
> Hi,
>
> 1) What is the size of an an empty class? On my machine it is showing
> 1. What is stored at that 1 byte memory?
> 2) will sizeof() function ever return zero?
> 3)How constructor/destructor are called when an object is created?
>    Any hidden virables will be crerated by the compiler inside the class?
> 4) Why destructor of derived class is not called when we delete a
> baseclass pointer which is pointing to derived class?
>
> Thansk in advance.
>



More information about the Gcc-help mailing list