From: Junio C Hamano <gitster@pobox•com>
To: git@vger•kernel.org
Subject: [PATCH] 3.0: require C99 flexible-array member syntax
Date: Thu, 11 Dec 2025 19:16:13 +0900 [thread overview]
Message-ID: <xmqqbjk5e32q.fsf@gitster.g> (raw)
Before C99 syntax to express that the final member in a struct is an
array of unknown number of elements, i.e.,
struct {
...
T flexible_array[];
};
came along, GNU introduced their own extension to declare such a
member with 0 size, i.e.,
T flexible_array[0];
and the compilers that did not understand even that were given a way
to emulate it by wasting one element, i.e.,
T flexible_array[1];
As we are pushing more and more C99 language features, let's declare
the historical forms of flexible array member support obsolete and
require C99 syntax from all compilers that want to compile Git.
Signed-off-by: Junio C Hamano <gitster@pobox•com>
---
Documentation/BreakingChanges.adoc | 3 +++
git-compat-util.h | 31 +++++++++++++++++--------------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git c/Documentation/BreakingChanges.adoc w/Documentation/BreakingChanges.adoc
index f814450d2f..81ab3cd1d8 100644
--- c/Documentation/BreakingChanges.adoc
+++ w/Documentation/BreakingChanges.adoc
@@ -315,6 +315,9 @@ symbolic links are not supported on some platforms.
Note that only the writing side for such symbolic links is deprecated. Reading
such symbolic links is still supported for now.
+* Support for flexible array member emulation using FLEX_ARRAY macro
+ for compilers that do not understand C99 FAM syntax will be removed.
+
== Superseded features that will not be deprecated
Some features have gained newer replacements that aim to improve the design in
diff --git c/git-compat-util.h w/git-compat-util.h
index 398e0fac4f..cedd022396 100644
--- c/git-compat-util.h
+++ w/git-compat-util.h
@@ -38,7 +38,10 @@ struct strbuf;
DISABLE_WARNING(-Wsign-compare)
#endif
-#ifndef FLEX_ARRAY
+#ifdef WITH_BREAKING_CHANGES
+# define FLEX_ARRAY /* C99 FAM mandatory */
+#else
+# ifndef FLEX_ARRAY
/*
* See if our compiler is known to support flexible array members.
*/
@@ -50,25 +53,25 @@ DISABLE_WARNING(-Wsign-compare)
* here, we can fall back to use the "safer but a bit wasteful" one
* later.
*/
-#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
-#elif defined(__GNUC__)
-# if (__GNUC__ >= 3)
+# if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)
+# elif defined(__GNUC__)
+# if (__GNUC__ >= 3)
+# define FLEX_ARRAY /* empty */
+# else
+# define FLEX_ARRAY 0 /* older GNU extension */
+# endif
+# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define FLEX_ARRAY /* empty */
-# else
-# define FLEX_ARRAY 0 /* older GNU extension */
# endif
-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
-# define FLEX_ARRAY /* empty */
-#endif
/*
* Otherwise, default to safer but a bit wasteful traditional style
*/
-#ifndef FLEX_ARRAY
-# define FLEX_ARRAY 1
-#endif
-#endif
-
+# ifndef FLEX_ARRAY
+# define FLEX_ARRAY 1
+# endif
+# endif /* FLEX_ARRAY */
+#endif /* WITH_BREAKING_CHANGES */
/*
* BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
next reply other threads:[~2025-12-11 10:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-11 10:16 Junio C Hamano [this message]
2025-12-12 8:36 ` [PATCH] 3.0: require C99 flexible-array member syntax Patrick Steinhardt
2025-12-12 12:54 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbjk5e32q.fsf@gitster.g \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox