Skip to content

Commit 8e97399

Browse files
committed
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>
1 parent 137a0d0 commit 8e97399

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

git-compat-util.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@
44
#define _FILE_OFFSET_BITS 64
55

66
#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
1125
#endif
1226
#endif
1327

0 commit comments

Comments
 (0)