数据结构union大小的计算?
请问下,union大小是以里面成员的最大占用尺寸的那个变量为极大值的吗?
int _tmain(int argc, _TCHAR* argv[])
{
#define DOUBLEdouble
#define LONGlong
#define SHORTshort
#define CHARchar
#define ULONGunsigned long
#define USHORTunsigned short
#define UCHARunsigned char
typedef union record
{
LONG lIndex;
SHORT sLevel[6];
CHAR cPos;
} REC_S;
REC_S stMax, *pMax;
CHAR str[] = "Hello";
CHAR *pChar = str;
ULONG ulGrade = 10;
USHORT usClass = 10;
DOUBLE dWeight;
UCHAR *pCharArray[10][10];
//Sizeof(stMax/pMax/str/pChar/ulGrade/usClass/dWeight/pCharArray)的取值分别是多少?
int sz = 0;
sz = sizeof(stMax); //组合,以最大尺寸变量为准
printf("sizeof of it is = %d\n", sz);
sz = sizeof(pMax); //指针,32位机,4个字节
printf("sizeof of it is = %d\n", sz);
sz = sizeof(str); //数组,字符串长度包括尾端的\0
printf("sizeof of it is = %d\n", sz);
sz = sizeof(pChar); //指针,32位机,4个字节
printf("sizeof of it is = %d\n", sz);
sz = sizeof(ulGrade); //long,标准32,4个字节
printf("sizeof of it is = %d\n", sz);
sz = sizeof(usClass); //short,标准16,2个字节
printf("sizeof of it is = %d\n", sz);
sz = sizeof(dWeight); //double,标准64,8个字节
printf("sizeof of it is = %d\n", sz);
sz = sizeof(pCharArray); //指针数组,32位机,4个字节*个数
printf("sizeof of it is = %d\n", sz);
return 0;
}