@matheusbsbs / matheus-bagliano / commits / 8e97399149
Fork 0

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@pobox.com>

Junio C Hamano committed Nov 20, 2007 at 12:08 UTC 8e9739914972419baad820e76b44d9720ed885c2
1 file changed +18 -4
git-compat-util.h
+18 -4
@@ -4,10 +4,24 @@
4 #define _FILE_OFFSET_BITS 64
5
6 #ifndef FLEX_ARRAY
7 -#if defined(__GNUC__) && (__GNUC__ < 3)
8 -#define FLEX_ARRAY 0
9 -#else
10 -#define FLEX_ARRAY /* empty */
7 +/*
8 + * See if our compiler is known to support flexible array members.
9 + */
10 +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
11 +# define FLEX_ARRAY /* empty */
12 +#elif defined(__GNUC__)
13 +# if (__GNUC__ >= 3)
14 +# define FLEX_ARRAY /* empty */
15 +# else
16 +# define FLEX_ARRAY 0 /* older GNU extension */
17 +# endif
18 +#endif
19 +
20 +/*
21 + * Otherwise, default to safer but a bit wasteful traditional style
22 + */
23 +#ifndef FLEX_ARRAY
24 +# define FLEX_ARRAY 1
25 #endif
26 #endif
27