git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix definition of ARRAY_SIZE for non-gcc builds

From
Charles Bailey <charles@hashpling.org>
Date
Jun 24, 2015, 07:44 UTC
Message-ID
<1435131867-11361-1-git-send-email-charles@hashpling.org>
From: Charles Bailey <cbailey32@bloomberg.net>

The improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which is expands to a valid check for recent gcc versions and to 0 for older gcc versions but is not defined on non-gcc builds.

Non-gcc builds need this macro to expand to 0 as well. The current outer test (defined(__GNUC__) && (__GNUC__)) is a strictly weaker condition than the inner test (GIT_GNUC_PREREQ(3, 1)) so we can omit the outer test and cause the BARF_UNLESS_AN_ARRAY macro to be defined correctly on non-gcc builds as well as gcc builds with older versions.

Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
---

This fixes a build regression introduced in v2.4.4 so this patch is based off that tag.

 git-compat-util.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index b45c75f..8c2b7aa 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -58,15 +58,13 @@
 #define BUILD_ASSERT_OR_ZERO(cond) \
 	(sizeof(char [1 - 2*!(cond)]) - 1)
 
-#if defined(__GNUC__) && (__GNUC__ >= 3)
-# if GIT_GNUC_PREREQ(3, 1)
+#if GIT_GNUC_PREREQ(3, 1)
  /* &arr[0] degrades to a pointer: a different type from an array */
 # define BARF_UNLESS_AN_ARRAY(arr)						\
 	BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \
 							   __typeof__(&(arr)[0])))
-# else
-#  define BARF_UNLESS_AN_ARRAY(arr) 0
-# endif
+#else
+# define BARF_UNLESS_AN_ARRAY(arr) 0
 #endif
 /*
  * ARRAY_SIZE - get the number of elements in a visible array
-- 
2.4.0.53.g8440f74
Next: Charles Bailey
Message 1 of 3 in “Fix definition of ARRAY_SIZE for non-gcc builds”
  1. Fix definition of ARRAY_SIZE for non-gcc buildsCharles Bailey, Jun 24, 2015
  2. Fix definition of ARRAY_SIZE for non-gcc buildsCharles Bailey, Jun 24, 2015
  3. Charles BaileyJun 24, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.