Size of structs containing unions
- From: "luke" <lroluk1@xxxxxxxxx>
- Date: 30 Sep 2005 00:23:18 -0700
hi,
in Visula C++ 6.0 I have declared a struct like this:
typedef struct _WRITE_INPUT {
ULONG DeviceNumber;
ULONG RegisterNumber;
union {
USHORT ShortData;
UCHAR CharData;
};
} WRITE_INPUT;
I can't understand why, sizeof(WRITE_INPUT) returns 12. It should
return 10, shouldn't it?
sizeof(ULONG) = 4
sizeof(ULONG) = 4
sizeof(USHORT) = 2 (longest union field)
4 + 4 + 2 = 10
thanks
bye
luke
.
- Follow-Ups:
- Re: Size of structs containing unions
- From: Martin Ambuhl
- Re: Size of structs containing unions
- From: Keith Thompson
- Re: Size of structs containing unions
- From: Anand
- Re: Size of structs containing unions
- Prev by Date: Assembler vs Compiler vs Linker
- Next by Date: Re: Assembler vs Compiler vs Linker
- Previous by thread: Assembler vs Compiler vs Linker
- Next by thread: Re: Size of structs containing unions
- Index(es):
Relevant Pages
|