]> git.proxmox.com Git - ovs.git/commitdiff
compiler: Fix compilation when using VStudio 2015/2017
authorAlin Gabriel Serdean <aserdean@ovn.org>
Wed, 3 Apr 2019 12:01:55 +0000 (15:01 +0300)
committerAlin Gabriel Serdean <aserdean@ovn.org>
Tue, 16 Apr 2019 08:47:14 +0000 (11:47 +0300)
This is somewhat a regression of:
https://github.com/openvswitch/ovs/commit/27f141d44d95b4cabfd7eac47ace8d1201668b2c

The main issue using `offsetof` from <stddef.h> via the C compiler from
MSVC 2015/2017 has issues and is buggy:
https://bit.ly/2UvWwti

Until it is fixed, we define our own definition of `offsetof`.

Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Acked-by: Anand Kumar <kumaranand@vmware.com>
include/openvswitch/compiler.h

index c7cb9308d029a183c7a5e426ca4bdf941defca38..5289a70f6eadc6b5535afc71b175b4c20df5696a 100644 (file)
 #define OVS_PREFETCH_WRITE(addr)
 #endif
 
+/* Since Visual Studio 2015 there has been an effort to make offsetof a
+ * builtin_offsetof, unfortunately both implementation (the regular define and
+ * the built in one) are buggy and cause issues when using them via
+ * the C compiler.
+ * e.g.: https://bit.ly/2UvWwti
+ */
+#if _MSC_VER >= 1900
+#undef offsetof
+#define offsetof(type, member) \
+    ((size_t)((char *)&(((type *)0)->member) - (char *)0))
+#endif
+
 /* Build assertions.
  *
  * Use BUILD_ASSERT_DECL as a declaration or a statement, or BUILD_ASSERT as