博客:blog.focus-linux.net linuxfocus.blog.chinaunix.net
- struct my_type {
-
unsigned int flag;
-
#define MY_FLAG_1 0x1
-
#define MY_FLAG_2 0x2
-
#define MY_FLAG_3 0x4
- };
- struct my_type {
-
unsigned int flag1:1,
-
flag2:1,
-
flag3:1,
-
spare:29;
- };
- struct my_type t1, t2;
- t1.flag = t2.flag
- struct my_type t1, t2;
-
-
t1.flag1 = t2.flag1;
-
t2.flag2 = t2.flag2;
- t3.flag3 = t2.flag3;
- struct my_type {
-
union {
-
unsigned int flag1:1,
-
flag2:1,
-
flag3:1,
-
spare:33;
-
unsigned int all_flags;
-
};
-
};
-
-
-
struct my_type t1, t2;
-
- t1.all_flags = t2.all_flags;
- #include <stdlib.h>
-
#include <stdio.h>
-
#include <string.h>
-
-
struct my_type {
-
union {
-
unsigned int flag1:1,
-
flag2:1,
-
flag3:1,
-
spare:29;
-
unsigned int all_flags;
-
};
-
};
-
-
int main(void)
-
{
-
struct my_type t;
-
-
memset(&t, 0, sizeof(t));
-
t.flag1 = 1;
-
-
printf("%d %d %d\n", t.flag1, t.flag2, t.flag3);
-
-
return 0;
-
- }
- [fgao@fgao-vm-fc13 test]$ ./a.out
- 1 1 1
- #include <stdlib.h>
-
#include <stdio.h>
-
#include <string.h>
-
-
struct my_type {
-
union {
-
struct {
-
unsigned int flag1:1,
-
flag2:1,
-
flag3:1,
-
spare:29;
-
};
-
unsigned int all_flags;
-
};
-
};
-
-
int main(void)
-
{
-
struct my_type t;
-
-
memset(&t, 0, sizeof(t));
-
t.flag1 = 1;
-
-
printf("%d %d %d 0x%X\n", t.flag1, t.flag2, t.flag3, t.all_flags);
-
-
return 0;
-
- }