From: Tim Deegan Subject: Re: [PATCH 1/3] mini-os: add BUILD_BUG_ON() Date: Thu, 3 Jul 2014 11:58:18 +0200 Message-ID: <20140703095818.GA32669@deinos.phlegethon.org> References: <53B42ADE020000780001F94F@mail.emea.novell.com> <53B43275020000780001F9CD@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1X2dmY-0007nZ-MY for xen-devel@lists.xenproject.org; Thu, 03 Jul 2014 09:58:22 +0000 Content-Disposition: inline In-Reply-To: <53B43275020000780001F9CD@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: Jan Beulich Cc: xen-devel , Stefano Stabellini , Samuel Thibault List-Id: xen-devel@lists.xenproject.org At 15:25 +0100 on 02 Jul (1404311125), Jan Beulich wrote: > Just copy over what the hypervisor currently uses. Careful of licenses here, please. While there might be an argument that BUILD_BUG_ON is simple enough to be uncopyrightable (and indeed it looks like you wrote the current Xen implementation anyway), I don't think you can just lift the whole thing, comments and all, into a BSD-licensed file. Cheers, Tim. > 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" > > +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 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 > > > > mini-os: add BUILD_BUG_ON() > > 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" > > +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 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 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel