From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MzxhJ-0002CL-42 for qemu-devel@nongnu.org; Mon, 19 Oct 2009 15:15:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MzxhE-00029b-Cb for qemu-devel@nongnu.org; Mon, 19 Oct 2009 15:15:12 -0400 Received: from [199.232.76.173] (port=58073 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzxhE-00029P-73 for qemu-devel@nongnu.org; Mon, 19 Oct 2009 15:15:08 -0400 Received: from mail2.shareable.org ([80.68.89.115]:48389) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MzxhD-0002Kv-UU for qemu-devel@nongnu.org; Mon, 19 Oct 2009 15:15:08 -0400 Date: Mon, 19 Oct 2009 20:15:04 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Message-ID: <20091019191504.GA8157@shareable.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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: > * add VARRAY_UINT16_UNSAFE: unsafe here means that type checking is off > (a.k.a. as a cast in C). In this case the problem is that the last > element of one struct is int foo[0], and we allocate the right size > for the array we want. Problem? I haven't been able to abuse^Wuse > gcc + cpp + magic to typecheck that for vmstate: > > We have > struct FOO { > int32_t foo[0]; > } > We want to "compare the type of foo (t1) with int32_t (t2) > > ((t1(*)[n])0 - (t2*)0) > This one don't work, because we don't have 'n' > ((t1(**))0 - (t2*)0) > This don't work either because t1 is one array. > ((t1(*)[])0 - (t2*)0) > Too clever, imposible cast to on array type. > I tried some other variants, but have not able to get one that compiles. Since you mention GCC, is it ok to use GCC extensions? __typeof__(t1) often does the trick for this sort of thing where t1 alone does not compile, even if t1 is a type. __builtin_types_compatible_p(), __builtin_choose_exper and __attribute__((__error__)) are good for informative error messages. -- Jamie