标签:
// 位段大小的计算以及宏的应用 #include <stdio.h> #include <malloc.h> #define MAX_SIZE A+B struct _Record_Struct { unsigned char Env_Alarm_ID : 4; unsigned char Paral : 2; unsigned char state; unsigned char avail : 1; }*Env_Alarm_Record; int main() { int A = 2; int B = 3; struct _Record_Struct *pointer = (struct _Record_Struct*)malloc (sizeof(struct _Record_Struct) * MAX_SIZE); printf("%d\n", sizeof(struct _Record_Struct));//结构体大小是3 free(pointer); return 0; } // 3*2+3=9开辟出来9个字节的空间 <img src="http://img.blog.csdn.net/20150508174521965?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
标签:
原文地址:http://blog.csdn.net/zhaoyaqian552/article/details/45583199