Re: Size of structs containing unions
- From: Anand <Anand@xxxxxxxxxxxxxx>
- Date: Fri, 30 Sep 2005 13:32:26 +0530
luke wrote:
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
c.l.c FAQ #2.13 would answer your question .
- Follow-Ups:
- Re: Size of structs containing unions
- From: luke
- Re: Size of structs containing unions
- References:
- Size of structs containing unions
- From: luke
- Size of structs containing unions
- Prev by Date: Re: Assembler vs Compiler vs Linker
- Next by Date: performing a "deep copy" on a nested structure
- Previous by thread: Size of structs containing unions
- Next by thread: Re: Size of structs containing unions
- Index(es):