Re: C Question
Michal Nazarewicz <[email protected]>
| Newsgroups | org.kernel.vger.linux-c-programming |
|---|---|
| Message-ID | <[email protected]> |
Randi Botse <[email protected]> writes: > Hi All, > > Im looking at lscpu.c shipped by util-linux-ng-2.17, can you explain > me how the *vir_types[] declared, is this valid C declaration? > > /* virtualization types */ > enum { > VIRT_NONE = 0, > VIRT_PARA, > VIRT_FULL > }; > const char *virt_types[] = { > [VIRT_NONE] = N_("none"), > [VIRT_PARA] = N_("para"), > [VIRT_FULL] = N_("full") > }; As Xiaotian Feng said, N_(x) must be defined somewhere and additionally to this this definition uses a new syntax where you can specify indexes of elements you want to set value to, ie. the above is the same as: const char *virt_types[] = { [0] = N_("none"), [1] = N_("para"), [2] = N_("full") }; which in turn is the same as: const char *virt_types[] = { N_("none"), N_("para"), N_("full") }; The advantage of the new syntax is that you can specify values in any order and omit some. -- Best regards, _ _ .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--