From: "Jan Beulich" Subject: [PATCH 1/3] mini-os: add BUILD_BUG_ON() Date: Wed, 02 Jul 2014 15:25:25 +0100 Message-ID: <53B43275020000780001F9CD@mail.emea.novell.com> References: <53B42ADE020000780001F94F@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartDCEE3645.2__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X2LTT-0007Cr-G4 for xen-devel@lists.xenproject.org; Wed, 02 Jul 2014 14:25:27 +0000 In-Reply-To: <53B42ADE020000780001F94F@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Samuel Thibault , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartDCEE3645.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Just copy over what the hypervisor currently uses. Signed-off-by: Jan Beulich --- a/extras/mini-os/include/lib.h +++ b/extras/mini-os/include/lib.h @@ -54,6 +54,20 @@ #include #include "gntmap.h" =20 +#if __GNUC__ > 4 || (__GNUC__ =3D=3D 4 && __GNUC_MINOR__ >=3D 6) +/* Force a compilation error if condition is true */ +#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) +/* Force a compilation error if condition is true, but also produce a + result (of value 0 and type size_t), so the expression can be used + e.g. in a structure initializer (or where-ever else comma expressions + aren't permitted). */ +#define BUILD_BUG_ON_ZERO(cond) \ + sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); }) +#else +#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); }) +#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond)) +#endif + #ifdef HAVE_LIBC #include #include --=__PartDCEE3645.2__= Content-Type: text/plain; name="minios-build-bug-on.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="minios-build-bug-on.patch" mini-os: add BUILD_BUG_ON()=0A=0AJust copy over what the hypervisor = currently uses.=0A=0ASigned-off-by: Jan Beulich =0A=0A--= - a/extras/mini-os/include/lib.h=0A+++ b/extras/mini-os/include/lib.h=0A@@ = -54,6 +54,20 @@=0A #include =0A #include "gntmap.h"=0A= =0A+#if __GNUC__ > 4 || (__GNUC__ =3D=3D 4 && __GNUC_MINOR__ >=3D = 6)=0A+/* Force a compilation error if condition is true */=0A+#define = BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })=0A+/* = Force a compilation error if condition is true, but also produce a=0A+ = result (of value 0 and type size_t), so the expression can be used=0A+ = e.g. in a structure initializer (or where-ever else comma expressions=0A+ = aren't permitted). */=0A+#define BUILD_BUG_ON_ZERO(cond) \=0A+ = sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); })=0A+#else=0A+#de= fine BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); })=0A+#define = BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond))=0A+#endif=0A+=0A #ifdef = HAVE_LIBC=0A #include =0A #include =0A --=__PartDCEE3645.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartDCEE3645.2__=--