首页 > 其他 > 详细

共用体+结构体(2)

时间:2015-07-15 12:31:35      阅读:201      评论:0      收藏:0      [点我收藏+]

技术分享

#include <stdio.h>

typedef union
{
    unsigned long dwVal;

    struct
    {
        unsigned short int  LSB;    /* LSB word code */
        unsigned short int  MSB;    /* MSB word code */
    }Word;

    struct
    {
        unsigned char   byte0;        /* bit 7  ~  0 */
        unsigned char   byte1;        /* bit 15 ~  8 */
        unsigned char   byte2;        /* bit 23 ~ 16 */    
        unsigned char   byte3;        /* bit 31 ~ 24 */
    }Byte;

}ULONG;


void main()
{
    ULONG Data;

    Data.dwVal = 12345678;
    printf("Data.dwVal = %ld \n", Data.dwVal);
    printf("Data.Byte = %ld \n", Data.Byte);
    printf("Data.Word = %ld \n", Data.Word);

    printf("Data.Byte.byte3 = %d \n", Data.Byte.byte3);
    printf("Data.Byte.byte2 = %d \n", Data.Byte.byte2);
    printf("Data.Byte.byte1 = %d \n", Data.Byte.byte1);
    printf("Data.Byte.byte0 = %d \n", Data.Byte.byte0);


    printf("Data.Word.MSB = %d \n", Data.Word.MSB);
    printf("Data.Word.LSB = %d \n", Data.Word.LSB);

    printf("Sizeof____Data.dwVal = %d \n", sizeof(Data.dwVal));
    printf("Sizeof____Data.Byte = %d \n", sizeof(Data.Byte));
    printf("Sizeof____Data.Word = %d \n", sizeof(Data.Word));

    printf("Sizeof____Data.Byte.byte3 = %d \n", sizeof(Data.Byte.byte3));
    printf("Sizeof____Data.Byte.byte2 = %d \n", sizeof(Data.Byte.byte2));
    printf("Sizeof____Data.Byte.byte1 = %d \n", sizeof(Data.Byte.byte1));
    printf("Sizeof____Data.Byte.byte0 = %d \n", sizeof(Data.Byte.byte0));

    printf("Sizeof____Data.Word.MSB = %d \n", sizeof(Data.Word.MSB));
    printf("Sizeof____Data.Word.LSB = %d \n", sizeof(Data.Word.LSB));
}

 

共用体+结构体(2)

原文:http://www.cnblogs.com/zhangfan2014/p/4647675.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!