From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y3Vgq-00057E-4U for qemu-devel@nongnu.org; Tue, 23 Dec 2014 15:04:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y3Vgl-00041z-Sy for qemu-devel@nongnu.org; Tue, 23 Dec 2014 15:04:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54148) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y3Vgl-00041h-LM for qemu-devel@nongnu.org; Tue, 23 Dec 2014 15:04:15 -0500 Message-ID: <5499CABA.5080008@redhat.com> Date: Tue, 23 Dec 2014 13:04:10 -0700 From: Eric Blake MIME-Version: 1.0 References: <1419359069-16611-1-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1419359069-16611-1-git-send-email-peter.maydell@linaro.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rJStntqbCVQnXLeAXul5g0OmpPM3ArqsI" Subject: Re: [Qemu-devel] [PATCH] scripts/qapi-types.py: Add dummy member to empty structs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel@nongnu.org Cc: Markus Armbruster , Luiz Capitulino This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --rJStntqbCVQnXLeAXul5g0OmpPM3ArqsI Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/23/2014 11:24 AM, Peter Maydell wrote: > Make sure that all generated C structs have at least one field; this > avoids potential issues with attempting to malloc space for > zero-length structs in C (g_malloc(sizeof struct) would return NULL). > It also avoids an incompatibility with C++ (where an empty struct is > size 1); that isn't important to us now but might be in future. >=20 > Generated empty structures look like this: > struct Abort > { > char qapi_dummy_field_for_empty_struct; > }; >=20 > This silences clang warnings like: > ./qapi-types.h:3752:1: warning: empty struct has size 0 in C, size 1 in= C++ [-Wextern-c-compat] > struct Abort > ^ >=20 > Signed-off-by: Peter Maydell > --- > scripts/qapi-types.py | 8 ++++++++ > 1 file changed, 8 insertions(+) Reviewed-by: Eric Blake However, I'm a bit surprised that there is no testsuite coverage for this; it would be nice if we had at least one test that used an empty struct to prove that we continue to generate them and their visitors correctly. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --rJStntqbCVQnXLeAXul5g0OmpPM3ArqsI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJUmcq6AAoJEKeha0olJ0NqFiQH/Rc6kZ+H4hOS9/LUSgzo/iXW dEF2KaKXVs1AfoPPqYOfiVEkO3FXOOVanIOnIuUj+JB4X+E8hECwBO69MGVGVtUo psw2xHARt6ot8ZOe+MosW7PphzsS8BPfjMYd2kO3I9aiUP1P80pi8k190vnKhQIW sBpCFu6J0qlwk3ozOqcTni5ldiOUvO1fxsXLxbi6k1u1/bqcc3As7e7/961r/Z+X koGQ6BzMnhEJyjYpGGnI0CSQhEZld6UIU//qaUgRdsSxQibXTENOkPb7LDHFfpfV HILMDBEicwGIIjzPJTzcIWsgt03egOevkRGBftDwV3B/RL3ETEMnjZNZE/819ug= =3jBV -----END PGP SIGNATURE----- --rJStntqbCVQnXLeAXul5g0OmpPM3ArqsI--