具有datentype枚举和指针的struct的大小

时间:2015-08-27 12:12:06

标签: c++ struct enums sizeof

我使用函数sizeof()来获取结构的大小。结果显示40.我认为应该是56。  如果我删除PicFormat m_eformat;,则大小仍为40.如果我同时删除PicFormat m_eformat;Framerate m_eFramerate;,则大小为32.我不知道原因。 代码如下:

“capstruct.h”

    enum PicFormat
    {
        PIC_JPG  = 0,            
        PIC_RGBA = 1,           
        PIC_RGB  = 2            
    }; 

    typedef enum 
    {
        RATE_30_HZ  = 0,
        RATE_25_HZ  = 1,
        RATE_20_HZ  = 2,
        RATE_15_HZ  = 3,
        RATE_7_5_HZ = 4
    } Framerate;

    struct sCaptureStruct
    {
        unsigned char   m_mac[6];             
        unsigned long long  m_iHWtime;
        unsigned long long  m_iNbr;
        PicFormat       m_eformat;             
        Framerate       m_eFramerate;
        unsigned int    m_iImageSize;
        unsigned char * m_pBuffer;
    };

的main.cpp

#include "capstruct.h"
#include <iostream>
using namespace std;


void main()
{
    sCaptureStruct s;
    int n = sizeof(s);
    cout<<n<<endl;

}

0 个答案:

没有答案