在结合内的位填充

时间:2016-03-29 13:04:57

标签: c++ visual-studio

我正在使用visual studio 2010.这里的结构位于位16和23,24正在添加额外位(零)。我需要从union变量FRAME中读取数据。     我需要建议如何删除那些额外的位。

#include "stdafx.h"
using namespace std;
#include<iostream>
#pragma once


int _tmain(int argc, _TCHAR* argv[])
{
#pragma pack(1)
    typedef struct /* __declspec(align(1)) */ STTCADispCtrl
    {
        unsigned char label;
        unsigned char sdi : 2;
        unsigned char ia : 1;
        unsigned char As : 2;
        unsigned char Att : 1;
        unsigned char Dtif : 1;
        unsigned char Ac : 2;
        unsigned char Mil : 3;
        unsigned char R8 : 1;
        unsigned long R0to7 : 8;
        unsigned char ssm : 2;
        unsigned char parity : 1;
    }ST_TCAS_MODE_DISP_CTRL;


    typedef union FrameData
    {
        unsigned long FRAME;
        ST_TCAS_MODE_DISP_CTRL              tcas_Disp_ctrl;
    }FRAME_DATA;

    unsigned long fout;
    unsigned int size = 0;
    FRAME_DATA    Fdata;
    Fdata = { 0 };


    size = sizeof(Fdata.tcas_Disp_ctrl);

    cout << size << endl;

    return 0;
}

0 个答案:

没有答案