duobango-tinyNET,20121219,[unsigned unicast:1;]

阅读版本:2

tnet_utils.h

/**Address.
*/
typedef struct tnet_address_s
{
    TSK_DECLARE_OBJECT;

    tnet_family_t family;

    unsigned unicast:1;
    unsigned anycast:1;
    unsigned multicast:1;
    unsigned dnsserver:1;

    char* ip;
}
tnet_address_t;

语句unsigned unicast:1;
声明无符号数unicast,:1代表什么未知?【位变量,一般用于结构中】

经过测试,发现取值范围限定{0,1}

再次测试类似unsigned unicast:2;
{0,1,2,3}

依次假设,在合理范围内:unsigned:Number的范围=
2^0-1,2^Number-1

Number=1,0~1
Number=2,0~3

如果是无符号数
struct A
{
    int h:n;
}

n=1,h范围:{0,-1}
n=2,h范围:{0,1,-2,-1}
n=3,h范围:{0,1,2,3,-4,-3,-2,-1}
n=4,h范围:{0,1,2,3,4,5,6,7,-8,-7,-6,-5,-4,-3,-2,-1}

0-2^(Number-1)~2^(Number-1)-1

另外,直接定义int m:2;是错误的,暂时只晓得在struct下可以这么定义

你可能感兴趣的:(duobango-tinyNET,20121219,[unsigned unicast:1;])