Re: [PATCH] Fix "identifier redeclared" compilation error with SUN cc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Mares <mj@xxxxxx> writes:

> Do we really want to use empty FLEX_ARRAY only for a new gcc? Shouldn't
> we test for C99 instead (__STDC_VERSION__ >= 199901L) and only if it
> isn't C99, choose between 0 and 1 depending on gccness of the compiler?

How about doing it this way?

-- >8 --
[PATCH] git-compat-util.h: auto-adjust to compiler support of FLEX_ARRAY a bit better

When declaring a structure with a flexible array member, instead
of defaulting to the c99 syntax for non-gnu compilers (which
burned people with older compilers), default to the traditional
and more portable "member[1]; /* more */" syntax.

At the same time, other c99 compilers should be able to take
advantage of the modern syntax to flexible array members without
being gcc.  Check __STDC_VERSION__ for that.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 git-compat-util.h |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 276a437..454d25e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -4,10 +4,24 @@
 #define _FILE_OFFSET_BITS 64
 
 #ifndef FLEX_ARRAY
-#if defined(__GNUC__) && (__GNUC__ < 3)
-#define FLEX_ARRAY 0
-#else
-#define FLEX_ARRAY /* empty */
+/*
+ * See if our compiler is known to support flexible array members.
+ */
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+# define FLEX_ARRAY /* empty */
+#elif defined(__GNUC__)
+# if (__GNUC__ >= 3)
+#  define FLEX_ARRAY /* empty */
+# else
+#  define FLEX_ARRAY 0 /* older GNU extension */
+# endif
+#endif
+
+/*
+ * Otherwise, default to safer but a bit wasteful traditional style
+ */
+#ifndef FLEX_ARRAY
+# define FLEX_ARRAY 1
 #endif
 #endif
 
-- 
1.5.3.6.1797.g67f5d

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux