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

[PATCH v2 4/5] CodingGuidelines: mention C99 features we can't use

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 10, 2022, 20:37 UTC
Message-ID
<20221010203800.2154698-5-gitster@pobox.com>
In-Reply-To
<20221010203800.2154698-1-gitster@pobox.com>
From: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

The C99 section of the CodingGuidelines is a good overview of what we can use, but is sorely lacking in what we can't use. Something that comes up occasionally is the portability of %z.

Per [1] we couldn't use it for the longest time due to MSVC not supporting it, but nowadays by requiring C99 we rely on the MSVC version that does, but we can't use it yet because a C library that MinGW uses doesn't support it.

1. https://lore.kernel.org/git/a67e0fd8-4a14-16c9-9b57-3430440ef93c@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/CodingGuidelines | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index f9affc4050..9598b45f7e 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -235,6 +235,13 @@ For C programs:
    . since late 2021 with 44ba10d6, we have had variables declared in
      the for loop "for (int i = 0; i < 10; i++)".
 
+   New C99 features that we cannot use yet:
+
+   . %z and %zu as a printf() argument for a size_t (the %z being for
+     the POSIX-specific ssize_t). Instead you should use
+     printf("%"PRIuMAX, (uintmax_t)v).  These days the MSVC version we
+     rely on supports %z, but the C library used by MinGW does not.
+
  - Variables have to be declared at the beginning of the block, before
    the first statement (i.e. -Wdeclaration-after-statement).
 
-- 
2.38.0-167-gf9a88ca9e9
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 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.