{"thread":{"id":"64611","subject":"[PATCH] 3.0: require C99 flexible-array member syntax","startedAt":"2025-12-11T10:16:15Z","lastAt":"2025-12-12T12:54:18Z","messageCount":3,"participants":["Junio C Hamano","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"532040","messageId":"xmqqbjk5e32q.fsf@gitster.g","threadId":"64611","inReplyTo":null,"subject":"[PATCH] 3.0: require C99 flexible-array member syntax","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-12-11T10:16:13Z","receivedAt":"2025-12-11T10:16:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Before C99 syntax to express that the final member in a struct is an\narray of unknown number of elements, i.e.,\n\n\tstruct {\n\t\t...\n\t\tT flexible_array[];\n\t};\n\ncame along, GNU introduced their own extension to declare such a\nmember with 0 size, i.e.,\n\n\t\tT flexible_array[0];\n\nand the compilers that did not understand even that were given a way\nto emulate it by wasting one element, i.e.,\n\n\t\tT flexible_array[1];\n\nAs we are pushing more and more C99 language features, let's declare\nthe historical forms of flexible array member support obsolete and\nrequire C99 syntax from all compilers that want to compile Git.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/BreakingChanges.adoc |  3 +++\n git-compat-util.h                  | 31 +++++++++++++++++--------------\n 2 files changed, 20 insertions(+), 14 deletions(-)\n\ndiff --git c/Documentation/BreakingChanges.adoc w/Documentation/BreakingChanges.adoc\nindex f814450d2f..81ab3cd1d8 100644\n--- c/Documentation/BreakingChanges.adoc\n+++ w/Documentation/BreakingChanges.adoc\n@@ -315,6 +315,9 @@ symbolic links are not supported on some platforms.\n Note that only the writing side for such symbolic links is deprecated. Reading\n such symbolic links is still supported for now.\n \n+* Support for flexible array member emulation using FLEX_ARRAY macro\n+  for compilers that do not understand C99 FAM syntax will be removed.\n+\n == Superseded features that will not be deprecated\n \n Some features have gained newer replacements that aim to improve the design in\ndiff --git c/git-compat-util.h w/git-compat-util.h\nindex 398e0fac4f..cedd022396 100644\n--- c/git-compat-util.h\n+++ w/git-compat-util.h\n@@ -38,7 +38,10 @@ struct strbuf;\n DISABLE_WARNING(-Wsign-compare)\n #endif\n \n-#ifndef FLEX_ARRAY\n+#ifdef WITH_BREAKING_CHANGES\n+# define FLEX_ARRAY /* C99 FAM mandatory */\n+#else\n+# ifndef FLEX_ARRAY\n /*\n  * See if our compiler is known to support flexible array members.\n  */\n@@ -50,25 +53,25 @@ DISABLE_WARNING(-Wsign-compare)\n  * here, we can fall back to use the \"safer but a bit wasteful\" one\n  * later.\n  */\n-#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)\n-#elif defined(__GNUC__)\n-# if (__GNUC__ >= 3)\n+# if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)\n+# elif defined(__GNUC__)\n+#  if (__GNUC__ >= 3)\n+#   define FLEX_ARRAY /* empty */\n+#  else\n+#   define FLEX_ARRAY 0 /* older GNU extension */\n+#  endif\n+# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)\n #  define FLEX_ARRAY /* empty */\n-# else\n-#  define FLEX_ARRAY 0 /* older GNU extension */\n # endif\n-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)\n-# define FLEX_ARRAY /* empty */\n-#endif\n \n /*\n  * Otherwise, default to safer but a bit wasteful traditional style\n  */\n-#ifndef FLEX_ARRAY\n-# define FLEX_ARRAY 1\n-#endif\n-#endif\n-\n+# ifndef FLEX_ARRAY\n+#  define FLEX_ARRAY 1\n+# endif\n+# endif /* FLEX_ARRAY */\n+#endif /* WITH_BREAKING_CHANGES */\n \n /*\n  * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.\n"},{"id":"532062","messageId":"aTvT8A31tQFvCvtL@pks.im","threadId":"64611","inReplyTo":"xmqqbjk5e32q.fsf@gitster.g","subject":"Re: [PATCH] 3.0: require C99 flexible-array member syntax","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-12-12T08:36:00Z","receivedAt":"2025-12-12T08:36:06Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Dec 11, 2025 at 07:16:13PM +0900, Junio C Hamano wrote:\n> Before C99 syntax to express that the final member in a struct is an\n> array of unknown number of elements, i.e.,\n> \n> \tstruct {\n> \t\t...\n> \t\tT flexible_array[];\n> \t};\n> \n> came along, GNU introduced their own extension to declare such a\n> member with 0 size, i.e.,\n> \n> \t\tT flexible_array[0];\n> \n> and the compilers that did not understand even that were given a way\n> to emulate it by wasting one element, i.e.,\n> \n> \t\tT flexible_array[1];\n> \n> As we are pushing more and more C99 language features, let's declare\n> the historical forms of flexible array member support obsolete and\n> require C99 syntax from all compilers that want to compile Git.\n\nIs there any specific reason why this is tied to the 3.0 breaking\nchanges document? I would have expected that we introduce this change\nvia a test balloon like we usually do for new C features that we haven't\nused before. And we already are using C99 features, so I wouldn't\nconsider this change to be \"more breaking\" than any of the other C99\nfeatures we have introduced already.\n\nSo I wonder whether we should instead convert one of the sites that\ncurrently uses FLEX_ARRAY to use C99 flexible arrays unconditionally. On\nthe other hand we don't really gain much by doing that, as it is just as\neasy to adapt the FLEX_ARRAY definitions to unconditionally use C99\nflexible arrays. Both would boil down to a couple lines of changes,\nonly.\n\nIf we see that any platform out there doesn't support this feature we\ncan still roll back and maybe tie it to Git 3.0.\n\nThanks!\n\nPatrick\n"},{"id":"532068","messageId":"xmqqqzszc13d.fsf@gitster.g","threadId":"64611","inReplyTo":"aTvT8A31tQFvCvtL@pks.im","subject":"Re: [PATCH] 3.0: require C99 flexible-array member syntax","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-12-12T12:54:14Z","receivedAt":"2025-12-12T12:54:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> As we are pushing more and more C99 language features, let's declare\n>> the historical forms of flexible array member support obsolete and\n>> require C99 syntax from all compilers that want to compile Git.\n>\n> Is there any specific reason why this is tied to the 3.0 breaking\n> changes document?\n\nConvenience, mostly.\n\nIt is not like we weren't allowing use of an advanced syntax and\nthen trying to see if everybody can use it, which was perfect match\nfor our past \"weather balloon\" approach.  Rather, we know that many\nplatforms did not know how to grok fam[] with an empty brackets, and\nhave workarounds fam[0] and fam[1].  This change proposes to break\nthe platforms that has to rely on the latter.\n\n> So I wonder whether we should instead convert one of the sites that\n> currently uses FLEX_ARRAY to use C99 flexible arrays unconditionally.\n\nOK, that is easy enough.  Or just remove it altogether and see who\nscreams, like the attached.\n\n----- >8 -----\nSubject: [PATCH] FLEX_ARRAY: require platforms to support the C99 syntax\n\nBefore C99 syntax to express that the final member in a struct is an\narray of unknown number of elements, i.e.,\n\n\tstruct {\n\t\t...\n\t\tT flexible_array[];\n\t};\n\ncame along, GNU introduced their own extension to declare such a\nmember with 0 size, i.e.,\n\n\t\tT flexible_array[0];\n\nand the compilers that did not understand even that were given a way\nto emulate it by wasting one element, i.e.,\n\n\t\tT flexible_array[1];\n\nAs we are using more and more C99 language features, let's see if\nthe platforms that still need to resort to the historical forms of\nflexible array member support are still there, by forcing all the\nflex array definitions to use the C99 syntax and see if anybody\nscreams (in which case reverting the changes is rather easy).\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * In the longer term, I'd love to import the fortified memcpy()\n   invented for the Linux kernel project that takes advantage of\n   advanced compiler features like __builtin_object_dynamic_size()\n   and friends, and use of C99 flexible array syntax is a good first\n   step to make it happen.\n\n git-compat-util.h | 33 ++-------------------------------\n 1 file changed, 2 insertions(+), 31 deletions(-)\n\ndiff --git c/git-compat-util.h w/git-compat-util.h\nindex 398e0fac4f..8e3f3a58a3 100644\n--- c/git-compat-util.h\n+++ w/git-compat-util.h\n@@ -38,37 +38,8 @@ struct strbuf;\n DISABLE_WARNING(-Wsign-compare)\n #endif\n \n-#ifndef FLEX_ARRAY\n-/*\n- * See if our compiler is known to support flexible array members.\n- */\n-\n-/*\n- * Check vendor specific quirks first, before checking the\n- * __STDC_VERSION__, as vendor compilers can lie and we need to be\n- * able to work them around.  Note that by not defining FLEX_ARRAY\n- * here, we can fall back to use the \"safer but a bit wasteful\" one\n- * later.\n- */\n-#if defined(__SUNPRO_C) && (__SUNPRO_C <= 0x580)\n-#elif defined(__GNUC__)\n-# if (__GNUC__ >= 3)\n-#  define FLEX_ARRAY /* empty */\n-# else\n-#  define FLEX_ARRAY 0 /* older GNU extension */\n-# endif\n-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)\n-# define FLEX_ARRAY /* empty */\n-#endif\n-\n-/*\n- * Otherwise, default to safer but a bit wasteful traditional style\n- */\n-#ifndef FLEX_ARRAY\n-# define FLEX_ARRAY 1\n-#endif\n-#endif\n-\n+#undef FLEX_ARRAY\n+#define FLEX_ARRAY /* empty - weather balloon to require C99 FAM */\n \n /*\n  * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.\n"}]}