Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1796124rdb; Mon, 8 Jan 2024 10:24:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRHvWabyj+L3f8MnHAUk43Z+qOgthVAuecaaWYAy/oMlR+GqmncH/KLqWvIdA3YGYTrFOY X-Received: by 2002:a17:906:b287:b0:a28:a13e:2339 with SMTP id q7-20020a170906b28700b00a28a13e2339mr1686267ejz.61.1704738250917; Mon, 08 Jan 2024 10:24:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704738250; cv=none; d=google.com; s=arc-20160816; b=ROKvGBl1D8tNeNpO4GbXewodiyVbt2wsk4bzFnRW3LbC/JINVo7iUZK/ck0gTk5D8/ kV+QLzsqK64nkMEXm9drJvU+0E3Kxj/3lKfRinXNd7YleWlzxLgjLjFzjelOoNCZOtGT Vzsz58UjsKR4cG+gbFreA+gbWMaIug3E9XaGWwVEpA3nmSP6FaH8xHwFj/DtSm+XNFru KsOR2TsnjEFV72fH7c6uDeLH5F5DbV/juGNjptcQ8mAf47A8iZeC7hJrK+DjRCL0aAHQ B/xv7KxovUZxGrzlYU0pUtshKn/gNFUtfMl7d37x7GvQ5oE5Rdjy/7k0tuUbtybom6JQ GOzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:references:in-reply-to:subject:cc:to:from:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=b0oUuyFSfFJa1FDkZDT6shsSmU4RBwb5/aJ3DpV1BVg=; fh=REptynWOzR9sz0XLfLicok3XQ+0boQwxxVgc+ZwZKYg=; b=Ng8bOT0M/gLpjkLAb2cGG7lGK3yJTDURLHvLtrHEC834ODlJR/cnT+J79cXmZVaClz in8SaHrTFsWWgCfvxh5UegKBgiEF0x+Lgp7C0I/07JCmPZ5oeCqi9CKKni/wtuI0OY4o hLYYz/FC+yx8xGX4pF08MrSg7DNRAi4QwfqueENXiDWbmgGiphHSo28oBvGe62cZpt3w qGnYSb6qhXU2SkCPF7zT7tWchZ2IaJtg2GK0HSb7Uw5Fv0uSqkEcZXly+c7wKmSFXENI 85g7l2ZnGbJk4AgXO5IURV6A+/k2+VhtWGpd/n8zK2uvZqmEjAzErGLlO46u56xoWcoG Jm2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b="A/pEiq0N"; spf=pass (google.com: domain of linux-kernel+bounces-19955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id uz6-20020a170907118600b00a28ac1176c1si111441ejb.465.2024.01.08.10.24.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 10:24:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b="A/pEiq0N"; spf=pass (google.com: domain of linux-kernel+bounces-19955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19955-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A3C251F221CD for ; Mon, 8 Jan 2024 18:24:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9576254BE0; Mon, 8 Jan 2024 18:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=posteo.net header.i=@posteo.net header.b="A/pEiq0N" X-Original-To: linux-kernel@vger.kernel.org Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A21A55778 for ; Mon, 8 Jan 2024 18:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=posteo.net Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 5E9A4240028 for ; Mon, 8 Jan 2024 19:23:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704738205; bh=fwt/GANjNvWWtupqWsOG0MztgpT1y2UeL0pOsAIRuPg=; h=MIME-Version:Content-Transfer-Encoding:Date:From:To:Cc:Subject: Message-ID:From; b=A/pEiq0NY9RP7r3bCBdSIk7irRHQ7Gr3qKUQ4103zHQ+p4HvwshIxw84GG0tY2vVq bcCTmvSerBeDSl6t402vFLikEyLPzDxIcem1wllgvDlK1LQGOnt44zOTYjlffuEK4a 7fAOIKEo/XO+dRK4Q4tiSK231fdTEY/Gu/GFM4IkV32oBOjCcgtuhKYXL1sljpErWH bQ6lM4BUN4bnzq7ydIIF+n8HHsOs3XzZsGR1tyekrErKGoIzkM9G2txrQZQ7+V5IUZ bwImo7b7wrOKlVHzgpd6nTtbKrS8IngZ0jYBo5AbYWCB5GutT9FgL0tb8iV+mwkeg3 AXRMGYk1V/w4A== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T82Vy2MWRz6twD; Mon, 8 Jan 2024 19:23:21 +0100 (CET) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 08 Jan 2024 18:23:21 +0000 From: Yueh-Shun Li To: Jonathan Corbet Cc: Hu Haowen , Alex Shi , Yanteng Si , Randy Dunlap , workflows@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] coding-style: show how reusing macros prevents naming collisions In-Reply-To: <871qaryel9.fsf@meer.lwn.net> References: <107b6b5e-ca14-4b2b-ba2e-38ecd74c0ad3@infradead.org> <20240108160746.177421-1-shamrocklee@posteo.net> <20240108160746.177421-3-shamrocklee@posteo.net> <871qaryel9.fsf@meer.lwn.net> Message-ID: Dear Mr. Corbet, Thank you very much for your feed back. On 2024-01-09 00:28, Jonathan Corbet wrote: > Yueh-Shun Li writes: > >> In section "18) Don't re-invent the kernel macros" in "Linux kernel >> coding style": >> >> Show how reusing macros from shared headers prevents naming collisions >> using "stringify", the one of the most widely reinvented macro, as an >> example. >> >> This patch aims to provide a stronger reason to reuse shared macros, >> by showing the risk of improvised macro variants. >> >> Signed-off-by: Yueh-Shun Li >> --- >> Documentation/process/coding-style.rst | 22 ++++++++++++++++++++++ >> 1 file changed, 22 insertions(+) >> >> diff --git a/Documentation/process/coding-style.rst >> b/Documentation/process/coding-style.rst >> index 2504cb00a961..1e79aba4b346 100644 >> --- a/Documentation/process/coding-style.rst >> +++ b/Documentation/process/coding-style.rst >> @@ -1070,6 +1070,28 @@ Similarly, if you need to calculate the size of >> some structure member, use >> There are also ``min()`` and ``max()`` macros in >> ``include/linux/minmax.h`` >> that do strict type checking if you need them. >> >> +Using existing macros provided by the shared headers also prevents >> naming >> +collisions. For example, if one developer define in ``foo.h`` >> + >> +.. code-block:: c >> + >> + #define __stringify(x) __stringify_1(x) >> + #define __stringify_1(x) #x >> + >> +and another define in ``bar.h`` >> + >> +.. code-block:: c >> + >> + #define stringify(x) __stringify(x) >> + #define __stringify(x) #x >> + >> +When both headers are ``#include``-d into the same file, the >> facilities provided >> +by ``foo.h`` might be broken by ``bar.h``. >> + >> +If both ``foo.h`` and ``bar.h`` use the macro ``__stringify()`` >> provided by >> +``include/linux/stringify.h``, they wouldn't have stepped onto each >> other's >> +toes. >> + > > So everything we add to our documentation has a cost in terms of reader > attention. We ask people to read through a lot of material now, and > should only increase that ask for good reason. > > With that context, I have to wonder whether we really need to tell our > readers, who are supposed to be capable developers, that reuse can help > to avoid name collisions? > The motivation comes from existing inconsistency of the "__stringify()" macro definition between e.g. "samples/bpf/tracex5.bpf.c" and other files. I agree that increasing the length of the documentation without substantial benefits would not be helpful for the readers, and doubling the length of a section is too much for its purpose. Should I shorten it into one sentence, like ``` On the other hand, locally-defined variants, such as ``#define __stringify(x) #x``, could lead to naming collisions that break otherwise functioning facilities. ``` or just omit it in the next version of patches? > Thanks, > > jon Thank you for your time and guidance. Shamrock