Re: Size of structs containing unions



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?

Please check the FAQ before posting. You might find <http://www.eskimo.com/~scs/C-faq/q2.13.html> enlightening.

BTW: Avoid nonstandard typenames in postings. If ULONG, USHORT, and UCHAR are in fact unsigned long, unsigned short, and unsigned char, why not use the real typenames?
.




Relevant Pages

  • Re: WAOAOAOJIIIIPPPPPPIIIIIIII
    ... UCHAR Chs1; ... ULONG Start; ... USHORT ReservedSectors; ... PVOID MapAddress(PVOID DeviceExtension, ULONG Address, ULONG Size) ...
    (microsoft.public.windowsxp.embedded)
  • Re: How can I get PCI card Slot Number in my WDM driver?
    ... next question he's going to ask is why slot number in an XYZ motherboard is ... > USHORT VendorID; ... > UCHAR RevisionID; ... > ULONG Bar0; ...
    (microsoft.public.development.device.drivers)