C语言中结构体小技巧


 
1.在结构体中指定成员的大小:
typedef struct ST_TIME
{
    DWORD  second      :6;//  秒   1-60        
    DWORD  minute      :6;//  分   1-60        
    DWORD  hour        :5;//  时   1-24        
    DWORD  day         :5;//  日   1-31        
    DWORD  month       :4;//  月   1-12        
    DWORD  year        :6;//  年   2000-2063   
}TIME;

 

2.在声明中对结构体成员初始化:
typedef struct ST_INFO
{
    DWORD32  cnt; 
    BYTE     time[1024] ;

    ST_INFO()
    {
        cnt = 0 ;
        memset((char*)(&time[0]) , 0 , 1024 ) ;  
    }
}INFO;


你可能感兴趣的:(C语言中结构体小技巧)