Received: from eggs.gnu.org ([2001:4830:134:3::10]:49348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMp5m-0007k7-7g for qemu-devel@nongnu.org; Sat, 14 Feb 2015 21:37:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMp5j-0001IW-1L for qemu-devel@nongnu.org; Sat, 14 Feb 2015 21:37:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59213) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMp5i-0001IO-QM for qemu-devel@nongnu.org; Sat, 14 Feb 2015 21:37:50 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1F2bnmu007021 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sat, 14 Feb 2015 21:37:49 -0500 Date: Sun, 15 Feb 2015 10:37:46 +0800 From: Fam Zheng Message-ID: <20150215023746.GA16159@fam-t430.nay.redhat.com> References: <54DE97D2.20506@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54DE97D2.20506@redhat.com> Subject: Re: [Qemu-devel] Enum String Generator List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow Cc: qemu-devel On Fri, 02/13 19:33, John Snow wrote: > Just a stupid question: We don't have a macro facility in the current > codebase that generates both an enum and string table / lookup function > simultaneously, do we? > > Some things really do just wind up looking grossly inelegant in C, and this > is one of them. > There is in QAPI: fam@fam-t430:~/build/last$ grep -A 4 NewImageMode_lookup qapi-types.c const char *NewImageMode_lookup[] = { "existing", "absolute-paths", NULL, }; fam@fam-t430:~/build/last$ grep -C 10 -e NEW_IMAGE qapi-types.h ... extern const char *NewImageMode_lookup[]; typedef enum NewImageMode { NEW_IMAGE_MODE_EXISTING = 0, NEW_IMAGE_MODE_ABSOLUTE_PATHS = 1, NEW_IMAGE_MODE_MAX = 2, } NewImageMode; ... Is that what you want? Fam