From patchwork Fri Oct 7 09:30:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13000929 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 AE851C433FE for ; Fri, 7 Oct 2022 09:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229757AbiJGJat (ORCPT ); Fri, 7 Oct 2022 05:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229744AbiJGJaq (ORCPT ); Fri, 7 Oct 2022 05:30:46 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D79D57E9 for ; Fri, 7 Oct 2022 02:30:43 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id bv10so2821372wrb.4 for ; Fri, 07 Oct 2022 02:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1OBWqNhgnPEHTpjKB6QRdb9j9B3rt64J0IqiiBl3Ogk=; b=eNt5sA+G7kiXb/SDPjIwIue98sFZLHHp0fwPh0KmF36CPzf/BopyWlPAktB4TftBOc ieUo6d8qUeAtvU7G2HmTKyCtKKRfGgc7E+NVWk39IB2SN6gJplB7sqTsQLmym/Q0P6HC deVoR47nda72JNf9+KnyEv5iAd5zjaIYjSMMfEeU94vi3J+H+yyg5ZcA5qcjVnJfixnr JA18LcV6FC1PrCWM+aG8nsj2ykzGWPxWoLuWh63sFg6w7lHOvzjImn9AZ2Qes/JU0ROA qXwqTGjapA71CZxk32qwlOUq6eqjOenkBMUhGC+ZjkpKHl9QB0msXillK8HBmHzxslIz LjwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1OBWqNhgnPEHTpjKB6QRdb9j9B3rt64J0IqiiBl3Ogk=; b=NDr47qj1XOMVynq8vd5/I9/OYu+SntzSqHkAHhZ2g71E+yXo9enFUuNFXUp8Z5rZbQ JoNY2uRphrFFzZ554FMMhLICG7bgdRr8E0jGgCXBrOWLmg7FdzyO3p7+c6wc2mHmzL4X KfMUBahTVDTlnb6PCwji9rfaAWUrmVpKCB71V3w38jrOOz5dgxL3ANR95rjKqRPaYr3/ tOWdRY9y9JxCdTcCdBADHQqsKGQ0zXdLpUL+SKltvBJ3hDUSQs5wQ8JuOYM/bRYbU1Nt iImig8Mq4m80Auj23b7V7sujqKMg9ZIdWFujLgoI0/RC1iBokmiOk8BjW2M8OsprM94R 0WjQ== X-Gm-Message-State: ACrzQf37NHdnpmm7asuXd0J2tFd0uTfhGJb5raWFBficcxHXqgBazc9N vac5QprGrRnwEM19mf96V/e/knGwR+6feg== X-Google-Smtp-Source: AMsMyM5FdOQutmjJhYMXs2SLgp0evFEGDNWciP0ycX0pu0IibK5179h8pSEqkkj150k1mZhMRFLayw== X-Received: by 2002:a05:6000:1568:b0:22e:6691:57aa with SMTP id 8-20020a056000156800b0022e669157aamr2476509wrz.708.1665135041453; Fri, 07 Oct 2022 02:30:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o18-20020a1c7512000000b003b492753826sm1634945wmc.43.2022.10.07.02.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 02:30:40 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jeff King , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 1/5] CodingGuidelines: update for C99 Date: Fri, 7 Oct 2022 11:30:30 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.971.ge79ff6d20e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- Documentation/CodingGuidelines | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 9fca21cc5f9..386ca0a0d22 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 Fri Oct 7 09:30:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13000931 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 57811C433F5 for ; Fri, 7 Oct 2022 09:30:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbiJGJaw (ORCPT ); Fri, 7 Oct 2022 05:30:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbiJGJaq (ORCPT ); Fri, 7 Oct 2022 05:30:46 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A5AE31BF for ; Fri, 7 Oct 2022 02:30:45 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id bk15so6347660wrb.13 for ; Fri, 07 Oct 2022 02:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XCm3WGvF9XGA2N853MNnGYeBD9JeHf6YfnlCoEZFwns=; b=msBD+9U0KG9WgWAQdgA0tw/nyRZoC8CiZDKqxEihxFaBooholBO5PuYVaPrbuudvQU YXNZtg69Lo/U+M17ias+l8PJSIiYbUvyv56DLJLS/DMO5VrINw0C0YxaXAD3wlxznsDn +rL8QdMrdOXS3u3mBy5uRXiCJ4hT2/MwSgjDS9pD9bDGuEjLduMbbQTfzCP81cBoYry8 Wkk+PC+Obh9DH71i7ArYsyN+22/prO4SpIB9St56Mj4SaVqA1JucYBtHaHlOEcs2AeDc vzLj/pXPLRpyn/gB6zbopP2m2nC6WVx6hbP4zKLxq9tGeA7CyFxi82a9XmrN/NEg5IBE ISWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XCm3WGvF9XGA2N853MNnGYeBD9JeHf6YfnlCoEZFwns=; b=Ga7eJrnljh27D/5MGjIbFIxyPe7bBW+O6OWqk6BK7fLVtCxvxUPaF03BfS2Aqr33r0 FfM17AyY2TR9oT80b3vFwCp9c3h7rxohq5zsj0lAy3VHCMf6QfrtQa64DwzUvgR0us1w 8DodIg6caeMUHLvTVZ/mufesmWzW3QOegRdfvOnl4hU1K9CDmIQs7NT7mWedSqIQeZPq acPeiCSRbXyavvCROnjTCeYyLd1CxNeCP/Aj7dST7C74huA1ad00UPFcQ0FCaQBBSyw0 rRpbhbsVLcfVwbqVNFmyINPL+fxNp+Bhoq9oU90AqxJqB3Q9piyP9o/dl/wC3uMWDWUc 03tw== X-Gm-Message-State: ACrzQf0+5dOHLJFRSjm+5wRN2zgYNrcn2ghSqSZstzB/dJ7zkUrIeDkq 44HMYN7GhD1olyW5un2aFXdeGJ55N4QG1g== X-Google-Smtp-Source: AMsMyM5PsJ+D/S7Sl4n1a7v0OpmEjTK6uZcMlmd+LhXdO30Ce4tnDD5sSow5HIheSJ3F+x9WAc2XFw== X-Received: by 2002:a05:6000:18ad:b0:22a:f7b5:16f8 with SMTP id b13-20020a05600018ad00b0022af7b516f8mr2572208wri.305.1665135043227; Fri, 07 Oct 2022 02:30:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o18-20020a1c7512000000b003b492753826sm1634945wmc.43.2022.10.07.02.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 02:30:42 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jeff King , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 2/5] CodingGuidelines: mention dynamic C99 initializer elements Date: Fri, 7 Oct 2022 11:30:31 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.971.ge79ff6d20e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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 From patchwork Fri Oct 7 09:30:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13000932 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 6FAC6C433FE for ; Fri, 7 Oct 2022 09:30:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229826AbiJGJaz (ORCPT ); Fri, 7 Oct 2022 05:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229777AbiJGJat (ORCPT ); Fri, 7 Oct 2022 05:30:49 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F8E7B8C3F for ; Fri, 7 Oct 2022 02:30:47 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id bv10so2821714wrb.4 for ; Fri, 07 Oct 2022 02:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AWhK8WmwG6YLEC7geu3uZt3J3/uCWguqCGeUj6zNVLo=; b=jOJWAtdg2zbU59f+yo9FoMIWovFmefFtxgRO85NVqSAy1LPOsvFiUQWZWK4xEXO2bU 4jAvyPu8aDqZ1vhW/2YaKr9uAmasw/OJHHge1Smt+5Xa/Cq+wPtoaY2BG0Ju3oXBUB2u dk4SvJqf2ciU6mjXm+EuufGgViapGuR6Xmp3hk8QdUL6yMQOo95aomR5Ni5bDMWX8b7r jLvPiah73csn2oqoE599QRU8RtNdlGxNC44i+F2BTmueT+4PSmKIRQuhhhFGa1WR5+Oq 8sgmQ1sIgVL3n+DOwzRCNN5tcJwDsKKQ/L4NhPm/Nl+XZetm36pP1La7+OtxkeheljiG HBnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AWhK8WmwG6YLEC7geu3uZt3J3/uCWguqCGeUj6zNVLo=; b=FJiDOA67OIiNk+JUnBvK8LS5py5mgIRq0Upl/n2m75BVOLeKSIWskwpmo6ON1ahh+B EuJ308eMjO2nxeeZY7Plos93mVsmlsqlpJDKmFCrxtMNRxjrWA9cdT9QlLYuOaf22ukY MYas1JQP4GVSzjQSoVeAyZp/shlOs2pFw/hctqei9ggqoTDIJKaRkdU/Z5OiqX6I4Xro 6OOSD1/6eKbAxFn9dkGRuCNiucvDdyK1p7+gMGdapIXNUFIOrTNEMSY5ZlKg7af0e9et a/IZDeZNtWjPhmXFswQWpLeg2JTwJjSD5kWILOJhNaU6H2NkQtcNEPQbO1iFIxmwtzgH CcOQ== X-Gm-Message-State: ACrzQf0MYWLnT3p45v319zBvETXHSxDTzxd4nVY9kW1ZiKidN74AIoqq dTRLi0tqcZdVRoZSgCdJa/ianMHdmBeohQ== X-Google-Smtp-Source: AMsMyM7uuI8zvC6vsRvBa0eYvxNmoEcEAZ0wPar+vpSNVnh/v3kt3JAl6uysp5yazLiMWkol7XmGLA== X-Received: by 2002:a5d:558f:0:b0:22e:2fac:d550 with SMTP id i15-20020a5d558f000000b0022e2facd550mr2683421wrv.652.1665135045807; Fri, 07 Oct 2022 02:30:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o18-20020a1c7512000000b003b492753826sm1634945wmc.43.2022.10.07.02.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 02:30:43 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jeff King , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 3/5] CodingGuidelines: allow declaring variables in for loops Date: Fri, 7 Oct 2022 11:30:32 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.971.ge79ff6d20e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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, and revert the recent 6983f4e3b20 (test-parse-options.c: don't use for loop initial declaration, 2022-09-05). It's better to update the guidelines than to have back & forth churn like that, we clearly don't have portability issues related to this syntax. Signed-off-by: Ævar Arnfjörð Bjarmason --- Documentation/CodingGuidelines | 10 ++-------- revision.c | 7 ------- t/helper/test-parse-options.c | 3 +-- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 8afda28cfce..f9affc4050a 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 36e31942cee..8f2623b3b5a 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); diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index 506835521a4..f8a62d892d9 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -195,8 +195,7 @@ int cmd__parse_options(int argc, const char **argv) static void print_args(int argc, const char **argv) { - int i; - for (i = 0; i < argc; i++) + for (int i = 0; i < argc; i++) printf("arg %02d: %s\n", i, argv[i]); } From patchwork Fri Oct 7 09:30:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13000933 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 198B0C433FE for ; Fri, 7 Oct 2022 09:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229868AbiJGJa5 (ORCPT ); Fri, 7 Oct 2022 05:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229788AbiJGJau (ORCPT ); Fri, 7 Oct 2022 05:30:50 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC56C895A for ; Fri, 7 Oct 2022 02:30:49 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id b7so6378491wrq.9 for ; Fri, 07 Oct 2022 02:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LGxnu3CnM7qG1xh9SLlWBxngLcnMzF2xK1x7bJx6gpM=; b=gUv+wOnLnuo2PNeNOxbfDXq1uP/+niUG/TcL9/SLhKZCuJsVrbc0qwUgWzH7juXCqt OMFNDXO9S4RHXdZQqzTrj46Vv1XW4QKMFZ+Rom6DeDvLhsaw7m4Q21fhGIoAKNSIaqq+ q4qeRs9G3CMrAu8t2WeNFMqciqS4Fj9QIDW2lbB9pmpOODZLIf9o6l4awdV3hQ9JO69z utcluO96cXFMXx9jDq90G5DpAsdJBLYy1ekd0Nv/OI2NA+hGfzo5vZ6LGZsgch68p9Uf nrTKEVZtJ9wh3y9jaGeNopyLGXlcguQbKP1/hXwBOZcI2cADYgvCElfclxjxGAWVw7jg xgeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LGxnu3CnM7qG1xh9SLlWBxngLcnMzF2xK1x7bJx6gpM=; b=VjS3xoN7LAGAl+Dpsp9bHhZNTDDpr5rne0JFJ0R7zMm9Z2vHQW/LBqNYnCX9MVvaYc ZfU+fATFFRNmMCB7NdEVMVod1IRVrDfuZJnpZctbZSI8VzU2dIucmRbIOB388dOBL/1m yh0V5iSSsEnUCaee5VJKR0lpl6U33JP7VLliNBVQUx1dUOdGRDvtHPWy8GKb2mx/sn0B N147zYGgoXKJUwWFVW34vi0zOn0s0p7e/okRm8/bH6LOKq1ayxgrBMQQszGNoH4fJjp6 wtjn7hN5Q2YiTdmY6WEcgDgHpQx4BaGIiAAEPaggrpbsmkJrafZbgM6AhUODREprb+jq ZxCg== X-Gm-Message-State: ACrzQf0g7cto7P139c/ZNfWCjVfzgnGX29ydpPjWM+EQVHMA/9EXUPx6 KGIzL3j+41tgqfDJguchJfIyIikkw/j8zw== X-Google-Smtp-Source: AMsMyM4qh4ZoQ3+eGHajtz+G1dyII0IKVlhZjxKUhKlb6727sz9h95STRpoRORhRePtlmRCKX6tVrQ== X-Received: by 2002:a5d:5149:0:b0:22e:8b85:3d7d with SMTP id u9-20020a5d5149000000b0022e8b853d7dmr1706950wrt.55.1665135047562; Fri, 07 Oct 2022 02:30:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o18-20020a1c7512000000b003b492753826sm1634945wmc.43.2022.10.07.02.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 02:30:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jeff King , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 4/5] CodingGuidelines: mention C99 features we can't use Date: Fri, 7 Oct 2022 11:30:33 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.971.ge79ff6d20e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- Documentation/CodingGuidelines | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index f9affc4050a..893f960231f 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 Fri Oct 7 09:30:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 13000934 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 0847DC433FE for ; Fri, 7 Oct 2022 09:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229891AbiJGJa7 (ORCPT ); Fri, 7 Oct 2022 05:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229804AbiJGJax (ORCPT ); Fri, 7 Oct 2022 05:30:53 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09599E31BF for ; Fri, 7 Oct 2022 02:30:50 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id h189-20020a1c21c6000000b003bd44dc526fso623128wmh.3 for ; Fri, 07 Oct 2022 02:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RdbJF/1XjvDfgbD4G/puDa19Z1q/UZGh+wIQbY3SfhY=; b=i3zXKvOf6i34cVA+irRjRfT/s8bZgwOEFp5jSc+5eFvLICLAxbFruCek03SoREKsL5 /AafBHUvQMf7tXJQt6fHgtQMfyJ4ecaFBVb0/wG9Lx9+rzANzzIGGTotwfiXWuSyOJa4 ClYtF4kizt1w+RhsPSn3RI8YfE0DItPvkUgRBrBcdsUP9j+cvMWKaP/M9fch3TIMYsgO C2EosQ2iyELI4zRWCYf/eevpHtU46p/Q+Cm4gUx8ZSjNyFvXMrlmn15kjDcXftS2/DwA 7ElXh4I6JJMU5QgVcZh8jndPP4RNqwIQ0fx8dvIX2De93en02y48/oev1awqGF5waEiK VFKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RdbJF/1XjvDfgbD4G/puDa19Z1q/UZGh+wIQbY3SfhY=; b=dprhZhQZIn4bmuwR/ea6ernRnPWDyyfamFh142K7tvFyKnO9Khb3x5RRtf8SENqFce Vb2DTUCnRRv7Qo9KjEIIvwOwGpg5qCDJCuWW+7iab8+LMINsbSsmz0W+nQzJw8iB3SjE PVvaXJ4nXXB+E5Lc/cGShxvEavSpEAbZHcWvBNgrVvIOuuoSjWUwt+5089WCjSg0Ub6c ovw1U0t8LIxr8lPy4dXiV0meiB4oxac0e9AUlyRsNh/OhPA+HirJAytgtydZ/ujVyn4X CbPu6NKLvY38X3h6uuFFNe0yFxKsgOb4utE2UxRw4HZzkcXD96AHslSJ7gq6gwtyKDtX I6Ww== X-Gm-Message-State: ACrzQf3yDtl2kmNKdjfn2rbVXuwdRbz7YOXZExPY0yNhpYimJescrcll BBGkYrD+/H3o0NLZ+40l3vDRGsxDIQHOHg== X-Google-Smtp-Source: AMsMyM6f+FeR78NZjMciHyWQusPnnsQsgfaX2gqo42xFvz6rvoCQTM6Kcn/btuS1/JQLW2Ae0HdYRA== X-Received: by 2002:a1c:f20e:0:b0:3c2:5062:4017 with SMTP id s14-20020a1cf20e000000b003c250624017mr3615878wmc.175.1665135048920; Fri, 07 Oct 2022 02:30:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id o18-20020a1c7512000000b003b492753826sm1634945wmc.43.2022.10.07.02.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Oct 2022 02:30:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , =?utf-8?q?Ren=C3=A9_Scharfe?= , Jeff King , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH 5/5] CodingGuidelines: recommend against unportable C99 struct syntax Date: Fri, 7 Oct 2022 11:30:34 +0200 Message-Id: X-Mailer: git-send-email 2.38.0.971.ge79ff6d20e7 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- Documentation/CodingGuidelines | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index 893f960231f..65b608ca0a2 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).