3
unsigned char networkMask [sizeof (struct in6_addr)] = { [0 ... (sizeof (struct in6_addr) - 1)] = 0xff };
IPv6地址獲取功能?
(0...(sizeof))
在這裏代表什麼。這個數組是如何分配的。
unsigned char networkMask [sizeof (struct in6_addr)] = { [0 ... (sizeof (struct in6_addr) - 1)] = 0xff };
IPv6地址獲取功能?
(0...(sizeof))
在這裏代表什麼。這個數組是如何分配的。
此特定語法是designated initializer的GCC擴展。有了它,可以初始化一個這樣的數組:
unsigned char foo[<n>] = { [0 ... <n> - 1] = <k> };
。由此<n>
是成員的數量和<k>
是任何給定的部件值。
在已顯示的代碼,它初始化networkMask
陣列0xff
用於通過從sizeof(struct in6_addr) - 1
索引0
元件。換句話說,它初始化一個大小爲struct in6_addr
的數組,並將所有位設置爲1
。
這將是等效於此,因爲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 };