Chinaunix
标题:
位域疑问?
[打印本页]
作者:
_nosay
时间:
2017-04-11 22:57
标题:
位域疑问?
#include <stdio.h>
struct tcpflag
{
char syn:1,
ack:1,
psh:1,
urg:1,
rst:1,
fin:1,
idx:1, /* verified?? */
dir:1; /* verified?? */
};
struct test {
struct tcpflag flag;
};
int main()
{
struct test t = {{ .syn=1, .ack=1, .rst=1, }};
printf("%d,%d,%d,%d,%d,%d,%d,%d\n",
t.flag.syn, t.flag.ack, t.flag.psh, t.flag.urg, t.flag.rst, t.flag.fin, t.flag.idx, t.flag.dir);
return 0;
}
复制代码
运行结果:
[root@localhost 9]# ./a.out
-1,-1,0,0,-1,0,0,0
为什么是-1?
作者:
dreamtale90
时间:
2017-04-12 07:23
char,unsigned char的符号位问题?
作者:
_nosay
时间:
2017-04-12 10:58
回复
2#
dreamtale90
腻害
作者:
nswcfd
时间:
2017-04-13 10:34
unsigned,踩过这个坑
作者:
_nosay
时间:
2017-04-13 23:06
回复
4#
nswcfd
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2