Chinaunix
标题:
点位符,union一起使用,结果好意外
[打印本页]
作者:
_nosay
时间:
2018-06-05 14:53
标题:
点位符,union一起使用,结果好意外
#include <stdio.h>
struct test {
union {
unsigned int type:8,
length:24;
struct {
unsigned char type;
unsigned char length[3];
} shadow;
} v;
};
int main()
{
struct test t;
t.v.type = 1;
t.v.length = 0x020304;
printf("%u, %u\n", t.v.type, t.v.length);
return 0;
}
复制代码
作者:
_nosay
时间:
2018-06-05 14:55
回复
1#
_nosay
把结构体里的shadow注释掉,也是一样的结果,怎么破?
作者:
_nosay
时间:
2018-06-05 20:14
回复
2#
_nosay
unsigned int type:8,
length:24;
不是一个整体,也被"union"了。。
作者:
Godbach
时间:
2018-07-05 20:48
回复
1#
_nosay
LZ 好久不见了。现在那里高就?
作者:
_nosay
时间:
2018-07-05 22:33
回复
4#
Godbach
在个小公司
作者:
Godbach
时间:
2018-07-09 00:58
回复
5#
_nosay
具体做什么方向呢
作者:
_nosay
时间:
2018-07-11 20:23
回复
6#
Godbach
做安全产品,用于整合系统本身以及一些开源软件输出的安全信息,并不需要开发团队对安全有多深的了解,不过卖的还不错。
作者:
incle
时间:
2018-07-25 10:00
现在安全产品要跟硬件结合一起买吗?
作者:
_nosay
时间:
2018-08-17 16:21
回复
8#
incle
是的
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2