From: Keir Fraser <keir.xen@gmail.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>,
Paul Durrant <paul.durrant@citrix.com>
Cc: "xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH] Use new Xen public header for product numbers and names
Date: Mon, 01 Oct 2012 11:36:10 +0100 [thread overview]
Message-ID: <CC8F30AA.40525%keir.xen@gmail.com> (raw)
In-Reply-To: <20585.27847.174145.345965@mariner.uk.xensource.com>
On 01/10/2012 11:13, "Ian Jackson" <Ian.Jackson@eu.citrix.com> wrote:
> Paul Durrant writes ("RE: [Xen-devel] [PATCH] Use new Xen public header for
> product numbers and names"):
>> Ok. I'll come up with something we can use to define an array and
>> then we can iterate over that.
>
> Great.
>
>
> What do people think of this preprocessor approach, which I suggested
> earlier:
My usual way to do this would be to place the list in its own header file:
pvdrivers_list.h:
EACH(WINDOWS, 0x0001, "xensource-windows")
EACH(...)
...
Then e.g.,
#define EACH(name,num,string) PVDRIVERS_ID_##name = num,
enum {
#include "pvdrivers_list.h"
}
#undef EACH
Which is a bit more abstruse on the consuming side, but does avoid the list
itself being an ugly multi-line macro monster.
I don't have a strong opinion on this by the way. :) Just saying...
-- Keir
> #define PVDRIVERS_LIST(EACH) \
> EACH(WINDOWS, 0x0001 /* Citrix */, "xensource-windows") \
> ...
>
> That can be used to generate arrays, or switch statements, or
> whatever. For example in pvdrivers.h:
>
> #define PVDRIVERS_EACH_ENUM(name,num,string) \
> PVDRIVERS_ID_##name = num,
> enum {
> PVDRIVERS_LIST(PVDRIVERS_EACH_ENUM)
> };
>
> and then in qemu:
>
> #define PVDRIVERS_EACH_SWITCH(name,num,string) \
> case PVDRIVERS_ID_##name: product = string; break;
>
> switch (id) {
> PVDRIVERS_LIST(PVDRIVERS_EACH_SWITCH)
> default:
> sprintf blah blah
> }
>
>
> If the indirect macro trick is too abstruse it's also possible to do
> this:
>
> #define PVDRIVERS_LIST \
> PVDRIVERS_EACH(WINDOWS, 0x0001 /* Citrix */, "xensource-windows") \
> ...
>
> That can be used to generate arrays, or switch statements, or
> whatever. For example in pvdrivers.h:
>
> #define PVDRIVERS_EACH(name,num,string) \
> PVDRIVERS_ID_##name = num,
> enum {
> PVDRIVERS_LIST
> };
> #undef PVDRIVERS_EACH
>
> and then in qemu:
>
> #define PVDRIVERS_EACH(name,num,string) \
> case PVDRIVERS_ID_##name: product = string; break;
>
> switch (id) {
> PVDRIVERS_LIST
> default:
> sprintf blah blah
> }
>
> #undef PVDRIVERS_EACH
>
>
> A #define containing an array initialiser is the other obvious
> alternative although of course the macro-based approaches I sketch
> above can be used to define arrays but not vice versa.
>
>
> Ian.
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2012-10-01 10:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-26 13:54 [PATCH] Use new Xen public header for product numbers and names Paul Durrant
2012-09-28 17:55 ` Ian Jackson
2012-10-01 8:38 ` Paul Durrant
2012-10-01 10:13 ` Ian Jackson
2012-10-01 10:28 ` Paul Durrant
2012-10-01 10:40 ` [PATCH] Use new Xen public header for product numbers and names [and 1 more messages] Ian Jackson
2012-10-01 10:36 ` Keir Fraser [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-10-01 9:43 [PATCH] Use new Xen public header for product numbers and names Paul Durrant
2012-10-01 15:14 ` Ian Jackson
2012-10-01 16:08 ` Paul Durrant
2012-10-02 9:25 ` Ian Campbell
2012-09-26 12:33 Paul Durrant
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=CC8F30AA.40525%keir.xen@gmail.com \
--to=keir.xen@gmail.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=paul.durrant@citrix.com \
--cc=xen-devel@lists.xen.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).