What is the C syntax (used in Linux / net / bonding / bond_main.c drivers)?

I have written a lot of C before, but I do not understand this syntax:

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", }; 

The [...] = is what looks strange to me. (By the way, BOND_MODE_ROUNDROBIN , and the rest are macros that simply expand to integers.)

+7
c syntax linux
source share
3 answers

He called the designated initializers , which is introduced in C99. GCC also supports it as an extension.

It is used to initialize structures and arrays, see Assigned Initializers for details.

+9
source share

This is the designated initializer . This allows you to enter the contents of an array in random order.

+4
source share

Here the names are an array of char pointes.

These pointers point to a string stored in a read-only section.

And Initialization is performed using the Assigned Initializers methods.

Here you can initialize any array with any order of their index. These macros are the index of the array.

0
source share

All Articles