JR wrote:
> Take a look at TestStruct1 and TestStruct2. Clearly, the D2 part of
> the union is MUCH larger than the D1 portion. I would expect
> sizeof(TestStruct1)==sizeof(TestStruct2) but that is not the case
> using Microsoft Visual C++ 2003. Here is what I get
>
> sizeof(TestStruct1)==0x108
> sizeof(TestStruct2)==0x104
>
> Is this normal C++ compiler behavior, or a bug in the compiler?
The compiler is allowed to add padding bytes to the struct
to give types a valid alignment. So the behaviour of sizeof
is correct, albeit implementation defined.
Be careful, other compilers may give you different values,
even the expected equality, may it be 108 or 104.
> typedef struct _TestStruct1 {
> union {
> struct {
> unsigned __int64 n1;
This is an implementation defined type, the standard doesnt
define __int64.
hth
Christoph
|