unsigned char networkMask [sizeof (struct in6_addr)] = { [0 ... (sizeof (struct in6_addr) - 1)] = 0xff };
what does (0...(sizeof))
is representing here. How this array is allocated.
This particular syntax is a GCC extension of the designated initializer . 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.
In the code you have shown, it initializes the networkMask
array with 0xff
for elements from index 0
through sizeof(struct in6_addr) - 1
. In other words, it initializes an array with the size of struct in6_addr
and sets all bits to 1
.
It would be equivalent to this, given that an IPv6 address occupies 16 bytes:
unsigned char networkMask[sizeof(struct in6_addr)] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.