Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1731772rdb; Mon, 8 Jan 2024 08:28:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4jzIDK+wsUo6tc3rDILsnOVfGCMebL7G19GNsKhGxCBS5PpLNtglv7jqTPXyH3SICKjoj X-Received: by 2002:a05:6808:1294:b0:3bc:3c0f:b95 with SMTP id a20-20020a056808129400b003bc3c0f0b95mr5731164oiw.99.1704731325031; Mon, 08 Jan 2024 08:28:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704731325; cv=none; d=google.com; s=arc-20160816; b=C9FsqR/Rj1PnQ67yb8wVMVQgJL//Sy9+0qsUHGF3G5P7oFQrclcXyvAywJRDVwsmvU 0ACYnpik0xlUY12G/XcpyhJjNzs605ZTh2iJZ/p74ll+MJt/j+wkTiKJLfdVhUWeXWAZ inDk3Ix8jtCCDEn+tq0Bx6VFy4+6s4Z92X1fNHC/0E+W/EG1L9XzTn3MA1vdEy21pCa+ 1k2lbiGzul5n6BKHzrinNrLbT2TX7VnvP7bOunTscqkIgTQsPqdJQh1pyH449Vl1LdEd 2rtrw2/ybpIQnzOqVsBYGkq+NfdWD32m30pdirACQiDS9B9uDsIKqjbKU8d4UeFwRcpu hHWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature:dkim-filter; bh=wq9SjBGaG0x7BK6duWay1nTcX9VdeS5D83MxyhQYxH8=; fh=PisxPZs4PuxteDyCQqxPU0Am4nvu4WxX8CjJA45biOo=; b=VxrP0dFjH3JNBwVbWIEe0+qSb6gAYU2Lvghbpk3knaYKB/Lk3mtxcy2zSNgzRCKr2D uJWr4k5N3Nw02IFmufelug0ccyqWQCLVyysnbzM5/BbebQBjWpo0u7s09lkqQOmPkGqY wpmGbbisDUwbMbmANA668RVv25g2mb8LTAvBVYhuAdBaNkcQY+7qv1EYh1r4rH+xybEI 1czY32GKu4kNpaKynlVLWO4AvkkKjbYF53vZCqXyS4PtgcOKqjNTIRJI4zUt1Fg+7tDn 2v54M8owmZkUuDsIluUZQ0vIuyIMH1v1aT6Pkx30P8j0Mub38aI/RX9v/xcJIpxy91j/ rUYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=MdS1b4ha; spf=pass (google.com: domain of linux-kernel+bounces-19842-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19842-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lwn.net Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x7-20020a0cc507000000b0067f91bab6dasi207016qvi.233.2024.01.08.08.28.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 08:28:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19842-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=MdS1b4ha; spf=pass (google.com: domain of linux-kernel+bounces-19842-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19842-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=lwn.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BF1641C22F2D for ; Mon, 8 Jan 2024 16:28:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F29DF4776E; Mon, 8 Jan 2024 16:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lwn.net header.i=@lwn.net header.b="MdS1b4ha" X-Original-To: linux-kernel@vger.kernel.org Received: from ms.lwn.net (ms.lwn.net [45.79.88.28]) (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 7DBF253E16; Mon, 8 Jan 2024 16:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lwn.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lwn.net Received: from localhost (unknown [IPv6:2601:280:5e00:7e19::646]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ms.lwn.net (Postfix) with ESMTPSA id 4ECBC377; Mon, 8 Jan 2024 16:28:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 ms.lwn.net 4ECBC377 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lwn.net; s=20201203; t=1704731299; bh=wq9SjBGaG0x7BK6duWay1nTcX9VdeS5D83MxyhQYxH8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=MdS1b4haLNtmbhmLT7JQZh+oO6+6oYPvKiSi/216/qZqR9FBZKRiIjXGDEUoSv/2g mgwv13z4PKIUyupKtNmzwQgxiIy/KXfARS1OHCNib6jhFDnCW2m/yz0Mz125LOqWBS 9iApfqzUv519ZkGoEhIWT4Yrr/10qrp88v4qI2p6uLh0ohVY1O6BMdp21GY+r2HN4D crPUi0KOC56A42/3Bf4Dq5U63qh6uDNMSnvT3sKWj8yfSUiVpCnC3rDroNBrWS59El k04jHh3ntAEiHhL39g8M2RswQ4aK8NuPQsGxXClskWlUUHXGjLRrSHB20x2vaMHp3t jeoBAvshlQmFw== From: Jonathan Corbet To: Yueh-Shun Li Cc: Yueh-Shun Li , 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: <20240108160746.177421-3-shamrocklee@posteo.net> References: <107b6b5e-ca14-4b2b-ba2e-38ecd74c0ad3@infradead.org> <20240108160746.177421-1-shamrocklee@posteo.net> <20240108160746.177421-3-shamrocklee@posteo.net> Date: Mon, 08 Jan 2024 09:28:18 -0700 Message-ID: <871qaryel9.fsf@meer.lwn.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain 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? Thanks, jon