阅读:1143回复:4
晕乎乎,大家来看看这个结构体的大小到底是多少?
下面是一个和ATA SMART Attribute相对应的结构体:
typedef struct _INDIVIDUALATTRIBUTE { BYTE bAttribteID; struct { USHORT bPrefailure:1; USHORT bVendorSpecific:5; USHORT bReserved:10; } bStatusFlag; BYTE bAttributeValue; char bVendorSpecific[8]; } INDIVIDUALATTRIBUTE, *PINDIVIDUALATTRIBUTE; 我本意让它的大小为12,但是用sizeof一看居然是14! 请高手指点,多谢! 按照下面的参考定义的: Attribute ID number (0x01 to 0xFFh) 1 binary Rd only Status flags 2 bit flags Rd only Pre-failure/advisory bit Vendor specific (5 bits) reserved (10 bits) Attribute value (valid values from 0x01 to 0xFEh) 1 binary Rd only 0x00 invalid for attribute value - not to be used 0x01 minimum value 0x64 initial value for all attributes prior to any data collection 0xFD maximum value 0xFE value is not valid 0xFF invalid for attribute value - not to be used Vendor specific 8 binary Rd only Total bytes 12 |
|
沙发#
发布于:2004-05-19 12:11
这东西好象有个4字节对齐的问题,不同的编译器会有不同的结果!
|
|
|
板凳#
发布于:2004-05-19 12:54
我看应该是16个= 1 + 3*2 + 1 + 8,
12怎么算出来的,如果bStatusFlag 是union为12 字节对齐可以自己设置 |
|
|
地板#
发布于:2004-05-19 13:20
Attribute ID number (0x01 to 0xFFh) 1 binary Rd only
Status flags 2 bit flags Rd only Pre-failure/advisory bit Vendor specific (5 bits) reserved (10 bits) Attribute value (valid values from 0x01 to 0xFEh) 1 binary Rd only Total bytes 12 #pragma pack(1) typedef struct _INDIVIDUALATTRIBUTE { BYTE xx; USHORT xx; BYTE xx; BYTE xx[8]; }INDIVIDUALATTRIBUTE, *P... #pragma pack(pop) so, 1 + 2 + 1 + 8 = 12 |
|
地下室#
发布于:2004-05-19 13:22
这东西好象有个4字节对齐的问题,不同的编译器会有不同的结果! 多谢! |
|