[英]IPv6 address get function?
unsigned char networkMask [sizeof (struct in6_addr)] = { [0 ... (sizeof (struct in6_addr) - 1)] = 0xff };
what does (0...(sizeof))
is representing here. (0...(sizeof))
在这里代表什么。 How this array is allocated. 如何分配此数组。
This particular syntax is a GCC extension of the designated initializer . 此特定语法是指定初始值设定项的GCC扩展。 With it, you can initialize an array like this:
有了它,你可以像这样初始化一个数组:
unsigned char foo[<n>] = { [0 ... <n> - 1] = <k> };
Whereby <n>
is the number of members and <k>
is any given member value. 其中
<n>
是成员数, <k>
是任何给定成员值。
In the code you have shown, it initializes the networkMask
array with 0xff
for elements from index 0
through sizeof(struct in6_addr) - 1
. 在您显示的代码中,它使用
0xff
为从索引0
到sizeof(struct in6_addr) - 1
元素初始化networkMask
数组。 In other words, it initializes an array with the size of struct in6_addr
and sets all bits to 1
. 换句话说,它初始化一个
struct in6_addr
的数组,并将所有位设置为1
。
It would be equivalent to this, given that an IPv6 address occupies 16 bytes: 考虑到IPv6地址占用16个字节,它将等同于此:
unsigned char networkMask[sizeof(struct in6_addr)] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.