unsigned int a : 1;含义

typedef struct {   
} m; 
 
int main()
{
	printf("%d\n", sizeof(m));	
	return 0;
}
//结果vc6.0为1,dev c++为0
typedef struct { 
	unsigned int a : 1;  
	unsigned int b : 1;  
	unsigned int c : 1;  
} m;  
int main()
{
	m k;  
	k.a = 1;  
	k.b = 0;  
	k.c = 0;  

	printf("%d, %d, %d, %d\n", sizeof(k), k.a, k.b, k.c);  	
	return 0;
}
结果vc6.0与dev c++均为4、1、0、0
k.a = 2; //结果0
k.a = 3; //结果1
unsigned int a : 2; k.a = 2; 结果:2
unsigned int a : 2; k.a = 3; 结果:3
unsigned int a : 2; k.a = 4; 结果:0

你可能感兴趣的:(c开发)