Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp691026pxb; Sat, 6 Mar 2021 13:35:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJzY1IGa029ayQoYvZSjJalAeU7XVQPwD8djfO9ZxN864iYhoUOMl8Evlj3IGU1YEcNmV78O X-Received: by 2002:a05:6402:3047:: with SMTP id bu7mr15401714edb.227.1615066550119; Sat, 06 Mar 2021 13:35:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615066550; cv=none; d=google.com; s=arc-20160816; b=fWtrMzd/b0tRpPORjC1xwYCaI7lbUeUWwMbMofu2aWF/h6Go+3PkZaSPeoe7SxSixJ gEyCK8/aXIc5N5lNK5NjR/xA6T2IZMLmz9xWP56tRgULYaUcuaRO0f+UdK6zvwXadmLA 3fkRxxijL77Un0g+5F4vcbsIr5SB1tgZvD6CSUYx6d9EzHGqtwBkxc7Mp2x4vPMM0b+O nATaUzi/UnMo3AdISSFlfpFGjMQ2C4tdnFHudWSblHKyjV4N7h+kMJOpjl/aUzTZvZGA 5t0HeIqhVtFeoqJoOKJMFvaNQOXL/QMLZ35tYZSUP9JKi6wMqeX4XWNGreUNPqDTgrOp FajQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LYVEwzZhLwplYvENbyLDo2KBa4YyGfoYjQU60hfjeAE=; b=Ppd4heHYPq3KkZcK2eSCWZ/r9e0EWH4reGiu1ciFnsRf+Q7SnnA+trwiC6+mO+7Lkq cA3Diq7a54fc0f8BlsIic0rfd9MBXKjtpl6UHVGdEBd/M6IxOrdbzCRdsKLMrwfn/o+B +G+mqZ7lkCdjFr4WD2WOlprQcc+X66ggoWKY7uwSKs4ZcukhKe7mlhECx44hQRwTIYK8 v6fzb36FIRJIhxA13QihD8HAeLwzmPZl9g58CkoBAFG6B3vYcIV5RTmYZGy74mK2eNwh vNVITwPenH1dgSNrRZdVMhW5PI8QOGo3WCdVsUew99dn3d3HyW4meNoDBR/z/G9Wbrfq 5yRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GeeH1OYV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qk9si3935319ejb.474.2021.03.06.13.35.26; Sat, 06 Mar 2021 13:35:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GeeH1OYV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229642AbhCFVeS (ORCPT + 99 others); Sat, 6 Mar 2021 16:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbhCFVdr (ORCPT ); Sat, 6 Mar 2021 16:33:47 -0500 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B3BBC06175F for ; Sat, 6 Mar 2021 13:33:47 -0800 (PST) Received: by mail-lj1-x230.google.com with SMTP id h4so9659875ljl.0 for ; Sat, 06 Mar 2021 13:33:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LYVEwzZhLwplYvENbyLDo2KBa4YyGfoYjQU60hfjeAE=; b=GeeH1OYVzaLLpPl2mP61ssVSI2UKJSm1EAkx4xzkZr84Wr3Nw/f5sD6LgJlbRFyxab XJG71kajxiLs01yTxCoNiDag9LNe0hXYgp1l4gznLjO91ntuKW7+sxaYeot4ghuHupke 1pIs+cbYOLKakGudxCvKT4rmy2Fh4//V7dXYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LYVEwzZhLwplYvENbyLDo2KBa4YyGfoYjQU60hfjeAE=; b=q9Qblw0spjfZ0A2aDabJSrV8og/0fwHNPVm70D05K1ngQMJPWzlcKUOa3Pt4OpaFQb 4Dqbbr6FUV6bibBLE9n4BUMSrAj3iGZvn1MMqcA0LpvY5vCz+8DG+WEBXBAc5Bu8/L5H cH2eNcTPadT/nPVlSBUO+UeExXmZu7AqoDJDpN2qqrdmsYHZw2VJFATysKlGCwsoedJK q8P7dy9YzTOB331IL2BUX4m5Hvnu6Pm6E4SCRQhLdQtCbnFisiLZJej/yGQFBPb017mN Pvp+k4sTwBAkQJiX5VKaFmJFGl48NcsBheVjTy8wcaxTiagH63wGFgd3sQxSdzrd4OlQ +/JA== X-Gm-Message-State: AOAM532r7in0ELtu+0yneZVscKnAhrvMLwe+TbCoRwsl46YQX0XxIzBg BAoi5i/P2CG2H4GzEfo7x1XHUdQ9bKMlMg== X-Received: by 2002:a2e:89d4:: with SMTP id c20mr9463406ljk.169.1615066425030; Sat, 06 Mar 2021 13:33:45 -0800 (PST) Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com. [209.85.167.45]) by smtp.gmail.com with ESMTPSA id o20sm773675lfu.286.2021.03.06.13.33.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Mar 2021 13:33:44 -0800 (PST) Received: by mail-lf1-f45.google.com with SMTP id p21so12627960lfu.11 for ; Sat, 06 Mar 2021 13:33:43 -0800 (PST) X-Received: by 2002:a19:ed03:: with SMTP id y3mr9567287lfy.377.1615066423154; Sat, 06 Mar 2021 13:33:43 -0800 (PST) MIME-Version: 1.0 References: <877dmo10m3.fsf@tromey.com> <4835ec1d2ecc40b285596288a0df4f47@AcuMS.aculab.com> <44a0cc9cb5344add8ee4d91bffbf958f@AcuMS.aculab.com> In-Reply-To: From: Linus Torvalds Date: Sat, 6 Mar 2021 13:33:27 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 00/11] pragma once: treewide conversion To: Miguel Ojeda Cc: David Laight , Tom Tromey , Alexey Dobriyan , Luc Van Oostenryck , Linux Kernel Mailing List , Andrew Morton , Sparse Mailing-list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 6, 2021 at 5:07 AM Miguel Ojeda wrote: > > Concerning #pragma once: I actually would like to have a standard > #once directive if what is a "seen file" could be defined a bit more > precisely. I think it would be ok if you had something like #pragma once IDTOKEN which would basically act *exactly* as a "#ifndef IDTOKEN/#define IDTOKEN" with that final #endif at the end of the file. But even then it should have the rule that it must be the very first thing in the file (ignoring whitespace and pure comments). Then it would literally be just a cleaner and simpler version of the guarding logic, with none of the semantic confusion that #pragma once now has. Because I cannot see any other way to define what "seen file" really means. There's no sane "implied IDTOKEN" that I can see. It can't really be the pathname, because pathnames are actually really hard to turn into canonical form in user space thanks to things like symlinks. It can't be st_ino/st_dev stat information, because the C preprocessor isn't a "POSIX only" thing. It could be a "Ok, #pragma once only works if you don't have multiple ways to reach the same file, and you never have ambiguous include paths". But that's actually not all that unusual in real projects: you often have fairly complex include paths, you have C files that include the header in the same directory with just "filename.h", but it _could_ get included indirectly from _another_ header that gave a pathname relative to the project root, etc etc. This is not unrelated to another complete morass of horrible problems: precompiled header files. That feature had exactly the same reason for it as "#pragma once" - slow build speeds due to the cost of parsing complex header file hierarchies. And I guarantee that multiple compiler teams spent hundreds of person-years of effort on trying to make it work. And several compilers do support the notion. And they ALL have big warnings about when you should enable it, and when you shouldn't, and what things don't work if you use them, and about how it can cause really really subtle problems. Because it turns out that precompiled header files are a major pain and a major mistake. Some projects still use them, because they can be such a huge timesaver (again: particularly C++ projects that just have a "include everything" approach to headers because trying to separate things out is too hard). But they all come with huge warnings about how they break the actual real semantics of a compiler, and if you do _anything_ to change the build ("hey, I'd like to use a different compiler option"), things may or may not work. Linus