All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Nazarewicz <mina86@tlen.pl>
To: Randi Botse <nightdecoder@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: C Question
Date: Tue, 25 May 2010 13:41:26 +0200	[thread overview]
Message-ID: <87r5l09pjt.fsf@erwin.mina86.com> (raw)
In-Reply-To: <AANLkTimNataepVFhtn4kSv_kGv1wTBHMAOgeZTK0hgW-@mail.gmail.com> (Randi Botse's message of "Tue, 25 May 2010 17:08:52 +0700")

Randi Botse <nightdecoder@gmail.com> 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--

  parent reply	other threads:[~2010-05-25 11:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-25 10:08 C Question Randi Botse
2010-05-25 10:19 ` Xiaotian Feng
     [not found]   ` <AANLkTinTu94E7guvzjySpGjht2Hjw4aop4vRIVpHo9UL@mail.gmail.com>
2010-05-25 10:49     ` Randi Botse
2010-05-25 11:18 ` Uriel Corfa
2010-05-25 11:41 ` Michal Nazarewicz [this message]
2010-05-30 10:41   ` Randi Botse
2010-05-30 12:38     ` Michal Nazarewicz
2010-06-01 11:59       ` Randi Botse
2010-06-01 13:18         ` Glynn Clements
  -- strict thread matches above, loose matches on Subject: below --
2009-10-08  2:12 C question Rick Brown
2009-10-08  2:52 ` Manish Katiyar
2009-10-08  5:37   ` Kalpesh Rathod
2009-10-08  8:48   ` Michał Nazarewicz
2009-10-08  3:02 ` mayur nande
2009-10-08  5:43   ` sandeep lahane
1999-10-21  1:40 C++ Question ian reinhart geiser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r5l09pjt.fsf@erwin.mina86.com \
    --to=mina86@tlen.pl \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=nightdecoder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.