git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/5] CodingGuidelines: mention dynamic C99 initializer elements

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 7, 2022, 09:30 UTC
Message-ID
<patch-2.5-343ec223dff-20221007T092505Z-avarab@gmail.com>
In-Reply-To
<cover-0.5-00000000000-20221007T092505Z-avarab@gmail.com>

The first use of variables in initializer elements appears to have been 2b6854c863a (Cleanup variables in cat-file, 2007-04-21) released with v1.5.2.

Some of those caused portability issues, and e.g. that "cat-file" use was changed in 66dbfd55e38 (Rewrite dynamic structure initializations to runtime assignment, 2010-05-14) which went out with v1.7.2.

But curiously 66dbfd55e38 missed some of them, e.g. an archive.c use added in d5f53d6d6f2 (archive: complain about path specs that don't match anything, 2009-12-12), and another one in merge-index.c (later builtin/merge-index.c) in 0077138cd9d (Simplify some instances of run_command() by using run_command_v_opt()., 2009-06-08).

As far as I can tell there's been no point since 2b6854c863a in 2007 where a compiler that didn't support this has been able to compile git. Presumably 66dbfd55e38 was an attempt to make headway with wider portability that ultimately wasn't completed.

In any case, we are thoroughly reliant on this syntax at this point, so let's update the guidelines, see https://lore.kernel.org/git/xmqqy1tunjgp.fsf@gitster.g/ for the initial discussion.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/CodingGuidelines | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 386ca0a0d22..8afda28cfce 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -213,6 +213,11 @@ For C programs:
    compilers we target have only partial support for it. These are
    considered safe to use:
 
+   . since around 2007 with 2b6854c863a, we have been using
+     initializer elements which are not computable at load time. E.g.:
+
+	const char *args[] = {"constant", variable, NULL};
+
    . since early 2012 with e1327023ea, we have been using an enum
      definition whose last element is followed by a comma.  This, like
      an array initializer that ends with a trailing comma, can be used
-- 
2.38.0.971.ge79ff6d20e7
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 4 of 22 in “CodingGuidelines: various C99 updates”
  1. 0/5 CodingGuidelines: various C99 updatesÆvar Arnfjörð Bjarmason, Oct 7, 2022
  2. 1/5 CodingGuidelines: update for C99Ævar Arnfjörð Bjarmason, Oct 7, 2022
  3. Junio C HamanoOct 7, 2022
  4. 2/5 CodingGuidelines: mention dynamic C99 initializer elementsÆvar Arnfjörð Bjarmason, Oct 7, 2022
  5. 3/5 CodingGuidelines: allow declaring variables in for loopsÆvar Arnfjörð Bjarmason, Oct 7, 2022
  6. Junio C HamanoOct 7, 2022
  7. 4/5 CodingGuidelines: mention C99 features we can't useÆvar Arnfjörð Bjarmason, Oct 7, 2022
  8. Junio C HamanoOct 7, 2022
  9. 5/5 CodingGuidelines: recommend against unportable C99 struct syntaxÆvar Arnfjörð Bjarmason, Oct 7, 2022
  10. Junio C HamanoOct 7, 2022
  11. Junio C HamanoOct 7, 2022
  12. 0/5 CodingGUidelines: C99 updatesJunio C Hamano, Oct 10, 2022
  13. 1/5 CodingGuidelines: update for C99Junio C Hamano, Oct 10, 2022
  14. 2/5 CodingGuidelines: mention dynamic C99 initializer elementsJunio C Hamano, Oct 10, 2022
  15. 3/5 CodingGuidelines: allow declaring variables in for loopsJunio C Hamano, Oct 10, 2022
  16. 4/5 CodingGuidelines: mention C99 features we can't useJunio C Hamano, Oct 10, 2022
  17. 5/5 CodingGuidelines: recommend against unportable C99 struct syntaxJunio C Hamano, Oct 10, 2022
  18. Jeff KingOct 11, 2022
  19. Junio C HamanoOct 11, 2022
  20. Jeff KingOct 11, 2022
  21. Ævar Arnfjörð BjarmasonOct 11, 2022
  22. Junio C HamanoOct 11, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.