]> git.proxmox.com Git - mirror_qemu.git/commitdiff
compiler: expression version of QEMU_BUILD_BUG_ON
authorMichael S. Tsirkin <mst@redhat.com>
Wed, 18 Jan 2017 20:05:15 +0000 (22:05 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 1 Feb 2017 01:37:17 +0000 (03:37 +0200)
QEMU_BUILD_BUG_ON uses a typedef in order to be safe
to use outside functions, but sometimes it's useful
to have a version that can be used within an expression.
Following what Linux does, introduce QEMU_BUILD_BUG_ON_ZERO
that return zero after checking condition at build time.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
include/qemu/compiler.h

index 057639af431db5638e421650455351d01959e0a1..e0ce9ffb2814c6b4ef1c4ac5574f3d5057efe248 100644 (file)
@@ -97,6 +97,9 @@
 #define QEMU_BUILD_BUG_ON(x)
 #endif
 
+#define QEMU_BUILD_BUG_ON_ZERO(x) (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \
+                                   sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)))
+
 #if defined __GNUC__
 # if !QEMU_GNUC_PREREQ(4, 4)
    /* gcc versions before 4.4.x don't support gnu_printf, so use printf. */