Skip to content

Commit 442c27d

Browse files
avargitster
authored andcommitted
CodingGuidelines: mention dynamic C99 initializer elements
The first use of variables in initializer elements appears to have been 2b6854c (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 66dbfd5 (Rewrite dynamic structure initializations to runtime assignment, 2010-05-14) which went out with v1.7.2. But curiously 66dbfd5 missed some of them, e.g. an archive.c use added in d5f53d6 (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 0077138 (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 2b6854c in 2007 where a compiler that didn't support this has been able to compile git. Presumably 66dbfd5 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/[email protected]/ for the initial discussion. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e88a2d0 commit 442c27d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Documentation/CodingGuidelines

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ For C programs:
213213
compilers we target have only partial support for it. These are
214214
considered safe to use:
215215

216+
. since around 2007 with 2b6854c863a, we have been using
217+
initializer elements which are not computable at load time. E.g.:
218+
219+
const char *args[] = {"constant", variable, NULL};
220+
216221
. since early 2012 with e1327023ea, we have been using an enum
217222
definition whose last element is followed by a comma. This, like
218223
an array initializer that ends with a trailing comma, can be used

0 commit comments

Comments
 (0)