From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MzzWG-0000m7-Oj for qemu-devel@nongnu.org; Mon, 19 Oct 2009 17:11:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MzzWC-0000l7-3s for qemu-devel@nongnu.org; Mon, 19 Oct 2009 17:11:56 -0400 Received: from [199.232.76.173] (port=33781 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzzWB-0000l4-U9 for qemu-devel@nongnu.org; Mon, 19 Oct 2009 17:11:51 -0400 Received: from mail2.shareable.org ([80.68.89.115]:53916) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MzzWB-0004K2-JB for qemu-devel@nongnu.org; Mon, 19 Oct 2009 17:11:51 -0400 Date: Mon, 19 Oct 2009 22:11:49 +0100 From: Jamie Lokier Message-ID: <20091019211149.GB9954@shareable.org> References: <20091019191504.GA8157@shareable.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Subject: [Qemu-devel] Re: [PATCH 00/25] VMState cleanups and conversion of network drivers List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org Juan Quintela wrote: > I have good error messages, I don't have good ideas about how to trick > the compiler. Error messages are clear. > > Example: > > struct FOO { > unt16_t foo[0]; > } > #define vmstate_offset_pointer(_state, _field, _type) \ > (offsetof(_state, _field) + \ > type_check_pointer(_type, typeof_field(_state, _field))) > > Called with (after doing substitutions) > type_check_pointer(uint16_t, struct FOO, foo); > > Give that, we try several definitions for type_check_pointer: > > #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) > > Gives the following error: > > /scratch/qemu/hw/eeprom93xx.c:144: error: invalid operands to binary - > (have ‘uint16_t **’ and ‘uint16_t (*)[]’) > > Another try: > > #define type_check_pointer(t1,t2) ((t1(*)[])0 - (t2*)0) > > gives > > /scratch/qemu/hw/eeprom93xx.c:148: error: arithmetic on pointer to an incomplete type > > Another one: > > #define type_check_pointer(t1,t2) ((t1(*)[0])0 - (t2*)0) > > gives: > > /scratch/qemu/hw/eeprom93xx.c:151: error: initializer element is not constant > /scratch/qemu/hw/eeprom93xx.c:151: error: (near initialization for ‘vmstate_eeprom’) #define type_check_pointer(t1,t2) (0*sizeof((t1(*)[0])0 - (t2*)0)) Or if you want foo[] to work: #define type_check_pointer(t1,t2) (0*sizeof((t1(**)[])0 - (t2**)0)) Dubiously, but fortunately, the second one works with foo[] and foo[0] in GCC. Enjoy :-) -- Jamie