operator bit-fields
时间:2010-05-01 来源:masonzhang
define x86 。。。
# include
# include
struct date {unsigned d:5, m:4, y:14;}__attribute((__packed__)); //aligned 24bit
union xxx{
struct date m_date;
int i ;
};
// how to operator bit-fields
int
main(int argc,char * argv[]) {
printf(" %d " ,sizeof(struct date));
union xxx x;
x.i = 0xF88B7;// register just only 24bit
x;
printf(" %d %d %d",x.m_date.d,x.m_date.m,x.m_date.y);
struct date m_date ;
int i = 0xF88B7;
m_date = *(struct date * )(int *)&i;
printf(" %d %d %d",m_date.d,m_date.m,m_date.y);
exit(EXIT_SUCCESS);
}
# include
# include
struct date {unsigned d:5, m:4, y:14;}__attribute((__packed__)); //aligned 24bit
union xxx{
struct date m_date;
int i ;
};
// how to operator bit-fields
int
main(int argc,char * argv[]) {
printf(" %d " ,sizeof(struct date));
union xxx x;
x.i = 0xF88B7;// register just only 24bit
x;
printf(" %d %d %d",x.m_date.d,x.m_date.m,x.m_date.y);
struct date m_date ;
int i = 0xF88B7;
m_date = *(struct date * )(int *)&i;
printf(" %d %d %d",m_date.d,m_date.m,m_date.y);
exit(EXIT_SUCCESS);
}
相关阅读 更多 +