From patchwork Mon Oct 10 20:37:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13003244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DBF2C433FE for ; Mon, 10 Oct 2022 20:38:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229759AbiJJUiZ (ORCPT ); Mon, 10 Oct 2022 16:38:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbiJJUiI (ORCPT ); Mon, 10 Oct 2022 16:38:08 -0400 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A9B51F9CB for ; Mon, 10 Oct 2022 13:38:07 -0700 (PDT) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 023CC1BF49A; Mon, 10 Oct 2022 16:38:07 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=sasl; bh=Q0+i4xq8KR1D boKlzNjV6vPMbre3x4rk+VESFFoS2ro=; b=CPPKef+VTqtNdxCdCMDsy1DfV02d wtb7ELub+37scj0+OJAz4O9AEMNfiil/tGUacebE7DvQmr9kbGiAiamzcE72YWiW P9rLm3/6RYv0+X1BirJdxDnAe49J1ShGmUFtc4xY1E1XuSqRB0oLSfhD9c/pu1SW AMLE4YJz4h+X438= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id EF6471BF499; Mon, 10 Oct 2022 16:38:06 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.5.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 32CEA1BF498; Mon, 10 Oct 2022 16:38:04 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/5] CodingGuidelines: update for C99 Date: Mon, 10 Oct 2022 13:37:56 -0700 Message-Id: <20221010203800.2154698-2-gitster@pobox.com> X-Mailer: git-send-email 2.38.0-140-gc6454a6c7f In-Reply-To: <20221010203800.2154698-1-gitster@pobox.com> References: <20221010203800.2154698-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 7095460A-48DB-11ED-B9CB-B31D44D1D7AA-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Since 7bc341e21b5 (git-compat-util: add a test balloon for C99 support, 2021-12-01) we've had a hard dependency on C99, but the prose in CodingGuidelines was written under the assumption that we were using C89 with a few C99 features. As the updated prose notes we'd still like to hold off on novel C99 features, but let's make it clear that we target that C version, and then enumerate new C99 features that are safe to use. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 9fca21cc5f..386ca0a0d2 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -204,10 +204,14 @@ For C programs: by e.g. "echo DEVELOPER=1 >>config.mak". - We try to support a wide range of C compilers to compile Git with, - including old ones. You should not use features from newer C + including old ones. As of Git v2.35.0 Git requires C99 (we check + "__STDC_VERSION__"). You should not use features from a newer C standard, even if your compiler groks them. - There are a few exceptions to this guideline: + New C99 features have been phased in gradually, if something's new + in C99 but not used yet don't assume that it's safe to use, some + compilers we target have only partial support for it. These are + considered safe to use: . since early 2012 with e1327023ea, we have been using an enum definition whose last element is followed by a comma. This, like From patchwork Mon Oct 10 20:37:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13003245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AB5BC433F5 for ; Mon, 10 Oct 2022 20:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbiJJUi1 (ORCPT ); Mon, 10 Oct 2022 16:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbiJJUiM (ORCPT ); Mon, 10 Oct 2022 16:38:12 -0400 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5D2B636C for ; Mon, 10 Oct 2022 13:38:10 -0700 (PDT) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id C09C41CCF5B; Mon, 10 Oct 2022 16:38:09 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=sasl; bh=TsDv7o7OJEos UlIEU7hD8kRTEivMXRRa2jCLbMFj2rM=; b=eu7vX1WTSpGoK34ItH8Rya4sIXXA 6YOgIbaB/FsDxewpqg9xtVIYOJnxrEwDnSWu+1lbHPzC2KfUYFoDiz4zV9dy1CeZ AxrnpnAlhUeZ2wl5A2XuIAT6CzYbQa/wIm5w+GtsW5nB/ro+ctBX20w51RJdpX/r MF0ymbpMGV8icmk= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id B98F91CCF5A; Mon, 10 Oct 2022 16:38:09 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.5.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id F27051CCF59; Mon, 10 Oct 2022 16:38:06 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/5] CodingGuidelines: mention dynamic C99 initializer elements Date: Mon, 10 Oct 2022 13:37:57 -0700 Message-Id: <20221010203800.2154698-3-gitster@pobox.com> X-Mailer: git-send-email 2.38.0-140-gc6454a6c7f In-Reply-To: <20221010203800.2154698-1-gitster@pobox.com> References: <20221010203800.2154698-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 723EAEF6-48DB-11ED-A04E-C2DA088D43B2-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason 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 Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 386ca0a0d2..8afda28cfc 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 From patchwork Mon Oct 10 20:37:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13003246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF0BEC433FE for ; Mon, 10 Oct 2022 20:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbiJJUi2 (ORCPT ); Mon, 10 Oct 2022 16:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbiJJUiM (ORCPT ); Mon, 10 Oct 2022 16:38:12 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFC0D1FE for ; Mon, 10 Oct 2022 13:38:11 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id A078215E3D5; Mon, 10 Oct 2022 16:38:10 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=sasl; bh=kyg7o9ekyunt 7pnx69oJaubCNVMDblsjog6zYpJM+08=; b=xd2B3zNN/QrBMk4ewdCH4Ot5tNGF 4MglWlXN9foH5Pdek/gRwSxVpH0A13FDvX38+pECKK/2stf4wUwZRSQjeu3tLnvJ 0wKLzn6Ve+XgxSkVclrBXmz0U5+wZxyUd+VJON2Jf1AdGQpue9UOZ6Jtug3LmrKX W+SdMcnfvhy5FiI= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 98AEB15E3D4; Mon, 10 Oct 2022 16:38:10 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.5.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id E83EE15E3D3; Mon, 10 Oct 2022 16:38:09 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/5] CodingGuidelines: allow declaring variables in for loops Date: Mon, 10 Oct 2022 13:37:58 -0700 Message-Id: <20221010203800.2154698-4-gitster@pobox.com> X-Mailer: git-send-email 2.38.0-140-gc6454a6c7f In-Reply-To: <20221010203800.2154698-1-gitster@pobox.com> References: <20221010203800.2154698-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 74026368-48DB-11ED-A041-307A8E0A682E-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Since 44ba10d6712 (revision: use C99 declaration of variable in for() loop, 2021-11-14) released with v2.35.0 we've had a variable declared with in a for loop. Since then we've had inadvertent follow-ups to that with at least cb2607759e2 (merge-ort: store more specific conflict information, 2022-06-18) released with v2.38.0. As November 2022 is within the window of this upcoming release, let's update the guideline to allow this. We can have the promised "revisit" discussion while this patch cooks, and drop it if it turns out that it is still premature, which is not expected to happen at this moment. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 10 ++-------- revision.c | 7 ------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 8afda28cfc..f9affc4050 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -232,18 +232,12 @@ For C programs: . since early 2021 with 765dc168882, we have been using variadic macros, mostly for printf-like trace and debug macros. - These used to be forbidden, but we have not heard any breakage - report, and they are assumed to be safe. + . since late 2021 with 44ba10d6, we have had variables declared in + the for loop "for (int i = 0; i < 10; i++)". - Variables have to be declared at the beginning of the block, before the first statement (i.e. -Wdeclaration-after-statement). - - Declaring a variable in the for loop "for (int i = 0; i < 10; i++)" - is still not allowed in this codebase. We are in the process of - allowing it by waiting to see that 44ba10d6 (revision: use C99 - declaration of variable in for() loop, 2021-11-14) does not get - complaints. Let's revisit this around November 2022. - - NULL pointers shall be written as NULL, not as 0. - When declaring pointers, the star sides with the variable diff --git a/revision.c b/revision.c index 36e31942ce..8f2623b3b5 100644 --- a/revision.c +++ b/revision.c @@ -47,13 +47,6 @@ static inline int want_ancestry(const struct rev_info *revs); void show_object_with_name(FILE *out, struct object *obj, const char *name) { fprintf(out, "%s ", oid_to_hex(&obj->oid)); - /* - * This "for (const char *p = ..." is made as a first step towards - * making use of such declarations elsewhere in our codebase. If - * it causes compilation problems on your platform, please report - * it to the Git mailing list at git@vger.kernel.org. In the meantime, - * adding -std=gnu99 to CFLAGS may help if you are with older GCC. - */ for (const char *p = name; *p && *p != '\n'; p++) fputc(*p, out); fputc('\n', out); From patchwork Mon Oct 10 20:37:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13003247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7A5EC433F5 for ; Mon, 10 Oct 2022 20:38:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbiJJUia (ORCPT ); Mon, 10 Oct 2022 16:38:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbiJJUiN (ORCPT ); Mon, 10 Oct 2022 16:38:13 -0400 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E675EBF51 for ; Mon, 10 Oct 2022 13:38:12 -0700 (PDT) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 369D6143EB2; Mon, 10 Oct 2022 16:38:12 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=sasl; bh=fDstQLqyQdgA lVotFaGrpeqcGBxsYFce8TUwoLPos6k=; b=KcEmqGISPOHdQQgnxdhvo9fo5O88 p00awL1WlG6Vjk6qyAKi2v93kBfU0smepBt4Lm8AB4NXbLbxQzGTJtVBhBz0s1Lb urBwaPIegAXIMcgMLrQmd9FLL39wST91M2/p7iZdm0cjmGe0ZgE4VYIO6fQUZ12R IxfUOyRZd3nZkD8= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 2F382143EB0; Mon, 10 Oct 2022 16:38:12 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.5.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 9499B143EAF; Mon, 10 Oct 2022 16:38:11 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 4/5] CodingGuidelines: mention C99 features we can't use Date: Mon, 10 Oct 2022 13:37:59 -0700 Message-Id: <20221010203800.2154698-5-gitster@pobox.com> X-Mailer: git-send-email 2.38.0-140-gc6454a6c7f In-Reply-To: <20221010203800.2154698-1-gitster@pobox.com> References: <20221010203800.2154698-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 74FEB56E-48DB-11ED-A376-2AEEC5D8090B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason 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 Signed-off-by: Junio C Hamano --- 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). From patchwork Mon Oct 10 20:38:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13003248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04851C4332F for ; Mon, 10 Oct 2022 20:38:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229896AbiJJUic (ORCPT ); Mon, 10 Oct 2022 16:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbiJJUiQ (ORCPT ); Mon, 10 Oct 2022 16:38:16 -0400 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4664E2B9 for ; Mon, 10 Oct 2022 13:38:16 -0700 (PDT) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id E0B621BF4A0; Mon, 10 Oct 2022 16:38:15 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-type:content-transfer-encoding; s=sasl; bh=0t2/B4ZNSSyi VOHKOxIAywRKIHfiqJfuouhFjYx13qE=; b=Hz4TNkM1zVfcYo0x++kY7sqLlDLq sj9LlQtX5KDEHexPeaPojrmUiYJiYXVF8uXQl8es7FABNgw3avleOGy3NbJL27Y9 /GCiRYTpK0sZmPKId5ZH/xUoy+HdJT383t57WtaulTwEjQAVnLWWiBF+EckXBf+0 nUeYeLETYDqAR8U= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id DABBA1BF49F; Mon, 10 Oct 2022 16:38:15 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.5.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 2001F1BF49C; Mon, 10 Oct 2022 16:38:13 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 5/5] CodingGuidelines: recommend against unportable C99 struct syntax Date: Mon, 10 Oct 2022 13:38:00 -0700 Message-Id: <20221010203800.2154698-6-gitster@pobox.com> X-Mailer: git-send-email 2.38.0-140-gc6454a6c7f In-Reply-To: <20221010203800.2154698-1-gitster@pobox.com> References: <20221010203800.2154698-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 75E6CCA0-48DB-11ED-8E00-B31D44D1D7AA-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Per 33665d98e6b (reftable: make assignments portable to AIX xlc v12.01, 2022-03-28) forms like ".a.b = *c" can be replaced by using ".a = { .b = *c }" instead. We'll probably allow these sooner than later, but since the workaround is trivial let's note it among the C99 features we'd like to hold off on for now. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- Documentation/CodingGuidelines | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 9598b45f7e..cbe0377699 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -242,6 +242,10 @@ For C programs: printf("%"PRIuMAX, (uintmax_t)v). These days the MSVC version we rely on supports %z, but the C library used by MinGW does not. + . Shorthand like ".a.b = *c" in struct assignments is known to trip + up an older IBM XLC version, use ".a = { .b = *c }" instead. See + the 33665d98e6b portability fix from mid-2022. + - Variables have to be declared at the beginning of the block, before the first statement (i.e. -Wdeclaration-after-statement).