From: Ian Jackson Subject: Re: [PATCH] Use new Xen public header for product numbers and names Date: Mon, 1 Oct 2012 11:13:27 +0100 Message-ID: <20585.27847.174145.345965@mariner.uk.xensource.com> References: <1348667684-29202-1-git-send-email-paul.durrant@citrix.com> <20581.58542.402088.878499@mariner.uk.xensource.com> <291EDFCB1E9E224A99088639C4762022EFF91D9EE4@LONPMAILBOX01.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <291EDFCB1E9E224A99088639C4762022EFF91D9EE4@LONPMAILBOX01.citrite.net> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Paul Durrant Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org 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: #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.