types: Define OVS_*128_MAX statically.
authorJoe Stringer <joe@ovn.org>
Mon, 21 Dec 2015 23:56:40 +0000 (15:56 -0800)
committerJoe Stringer <joe@ovn.org>
Tue, 22 Dec 2015 17:51:17 +0000 (09:51 -0800)
The previous definitions of these variables using designated
initializers caused a variety of issues when attempting to compile with
MSVC, particularly if including these headers from C++ code. By defining
them like this, we can appease MSVC and keep the definitions the same on
all platforms.

VMware-BZ: #1517163
Suggested-by: Yin Lin <linyi@vmware.com>
Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
include/openvswitch/types.h
lib/util.h

index 32b27d0..658fb50 100644 (file)
@@ -99,8 +99,13 @@ typedef union {
     } be64;
 } ovs_be128;
 
-#define OVS_U128_MAX (ovs_u128) { .u64 = { UINT64_MAX, UINT64_MAX } }
-#define OVS_BE128_MAX (ovs_be128) { .be64 = { OVS_BE64_MAX, OVS_BE64_MAX } }
+/* MSVC2015 doesn't support designated initializers when compiling C++,
+ * and doesn't support ternary operators with non-designated initializers.
+ * So we use these static definitions rather than using initializer macros. */
+static const ovs_u128 OVS_U128_MAX = { { UINT32_MAX, UINT32_MAX,
+                                         UINT32_MAX, UINT32_MAX } };
+static const ovs_be128 OVS_BE128_MAX = { { OVS_BE32_MAX, OVS_BE32_MAX,
+                                           OVS_BE32_MAX, OVS_BE32_MAX } };
 
 /* A 64-bit value, in network byte order, that is only aligned on a 32-bit
  * boundary. */
index 340ef65..2480583 100644 (file)
@@ -574,9 +574,7 @@ ovs_u128_is_zero(const ovs_u128 *val)
 static inline bool
 ovs_u128_is_ones(const ovs_u128 *val)
 {
-    ovs_u128 ones = OVS_U128_MAX;
-
-    return ovs_u128_equals(val, &ones);
+    return ovs_u128_equals(val, &OVS_U128_MAX);
 }
 
 /* Returns non-zero if the parameters have equal value. */