<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Jul 6, 2018, at 5:25 PM, <a href="mailto:janisozaur@gmail.com" class="">janisozaur@gmail.com</a> wrote:<br class=""><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div class="">From: Michał Janiszewski <<a href="mailto:janisozaur@gmail.com" class="">janisozaur@gmail.com</a>><br class=""><br class="">Inspired by kernel check and recent unification of ARRAY_SIZE, provide<br class="">a way of enforcing the macro can only be applied to actual arrays and<br class="">not to pointers.<br class=""><br class="">Signed-off-by: Michał Janiszewski <<a href="mailto:janisozaur@gmail.com" class="">janisozaur@gmail.com</a>><br class="">---<br class=""> include/winnt.h | 21 ++++++++++++++++++++-<br class=""> 1 file changed, 20 insertions(+), 1 deletion(-)<br class=""><br class="">diff --git a/include/winnt.h b/include/winnt.h<br class="">index 7f822c4aec..ad945464f1 100644<br class="">--- a/include/winnt.h<br class="">+++ b/include/winnt.h<br class="">@@ -760,7 +760,26 @@ typedef struct _MEMORY_BASIC_INFORMATION<br class="">   ((type *)((PCHAR)(address) - offsetof(type, field)))<br class=""><br class=""> #ifdef __WINESRC__<br class="">-# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))<br class="">+// Validate types used in the expression.<br class="">+// Based on <a href="https://elixir.bootlin.com/linux/v4.17.4/source/include/linux/kernel.h#L71" class="">https://elixir.bootlin.com/linux/v4.17.4/source/include/linux/kernel.h#L71</a><br class=""></div></div></blockquote><div><br class=""></div><div>Does that pose a licensing issue, since that code is GPL?</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class="">+<br class="">+#ifdef __GNUC__<br class="">+/**<br class="">+ * Force a compilation error if condition is true, but also produce a<br class="">+ * result (of value 0 and type size_t), so the expression can be used<br class="">+ * e.g. in a structure initializer (or where-ever else comma expressions<br class="">+ * aren't permitted).<br class="">+ */<br class="">+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))<br class="">+<br class="">+/* &a[0] degrades to a pointer: a different type from an array */<br class="">+#define __must_be_array(a) \<br class="">+    BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))<br class=""></div></div></blockquote><div><br class=""></div><div>In what version of GCC was __builtin_types_compatible_p() introduced?</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">+#else<br class="">+#define __must_be_array(a) 0<br class="">+#endif<br class="">+<br class="">+# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + __must_be_array(x)<br class=""></div></div></blockquote><div><br class=""></div><div>The " + __must_be_array(x)" should be inside the parentheses.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""> #endif</div></div></blockquote><br class=""></div>-Ken<div class=""><br class=""></div></body></html>