我以前写了很多C,但是我不认识这个语法:
static const char *names[] = { [BOND_MODE_ROUNDROBIN] = "load balancing (round-robin)",[BOND_MODE_ACTIVEBACKUP] = "fault-tolerance (active-backup)",[BOND_MODE_XOR] = "load balancing (xor)",[BOND_MODE_BROADCAST] = "fault-tolerance (broadcast)",[BOND_MODE_8023AD] = "IEEE 802.3ad Dynamic link aggregation",[BOND_MODE_TLB] = "transmit load balancing",[BOND_MODE_ALB] = "adaptive load balancing",};
[…] =部分对我来说很奇怪. (顺便说一句,BOND_MODE_ROUNDROBIN和其他是只扩展为整数的宏.)
解决方法
它被称为指定的初始化器,在C99中引入. GCC也支持它作为扩展.
它用于初始化结构和数组,详见Designated Initializers.