Skip to content

Commit deefc2d

Browse files
committed
flex-array: simplify compiler-specific workaround
We use "type array[];" syntax for the flex-array member at the end of a struct under C99 or later, except when we are building with older SUNPRO_C compilers. As we find more vendor compilers that claim to grok C99 but not understand the flex-array syntax, the existing "If we are using C99, but not with these compilers..." conditional will keep growing. Make it more manageable by listing vendor-specific exceptions earlier, with the expectation that new exceptions will not be combined into existing ones to make the condition longer, and instead will be implemented as a new "#elif" in the cascade of similar to old SUNPRO_C, we can just add a single line #elif defined(_MSC_VER) immediately before "#elif defined(__GNUC__)" to cause us to fallback to the safer but a bit wasteful version. Signed-off-by: Junio C Hamano <[email protected]>
1 parent e9d7761 commit deefc2d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

git-compat-util.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@
3333
/*
3434
* See if our compiler is known to support flexible array members.
3535
*/
36-
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && (!defined(__SUNPRO_C) || (__SUNPRO_C > 0x580))
37-
# define FLEX_ARRAY /* empty */
36+
37+
/*
38+
* Check vendor specific quirks first, before checking the
39+
* __STDC_VERSION__, as vendor compilers can lie and we need to be
40+
* able to work them around. Note that by not defining FLEX_ARRAY
41+
* here, we can fall back to use the "safer but a bit wasteful" one
42+
* later.
43+
*/
44+
#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
3845
#elif defined(__GNUC__)
3946
# if (__GNUC__ >= 3)
4047
# define FLEX_ARRAY /* empty */
4148
# else
4249
# define FLEX_ARRAY 0 /* older GNU extension */
4350
# endif
51+
#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
52+
# define FLEX_ARRAY /* empty */
4453
#endif
4554

4655
/*

0 commit comments

Comments
 (0)