C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Revising #pragma once

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Mon, 23 Sep 2024 11:04:22 +0300
On Mon, 23 Sept 2024 at 10:59, Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> I've been away for 5 weeks and it will take me ages to catch up on
> this discussion, but here's what I'm thinking:
>
> When the preprocessor encounters "#pragma once", do the following:
>
> For the remainder of the currently open file (i.e. for the remainder
> of the header file which is being pasted into the translation unit),
> replace all "\r\n" line endings with "\n" line endings, and then
> remove all trailing newline characters from the end of the header
> file. Calculate the hash digest of the remaining text and add it to a
> list of digests for "already included text". If the digest already
> exists in the list, then stop pasting the contents of the currently
> open file into the translation unit.
>
> I think it's important to replace the "\r\n" line endings before
> calculating the digest because code management tools like Git allow
> you to save a repository with "Windows line endings" or "Unix line
> endings" -- and a team of people could be collaborating using
> different PC's (e.g. Apple mac, MS-Windows). Also, some popular text
> editors such as Geany and Notepad++ automatically put a newline at the
> end of a file, so I say we disregard trailing newlines.

That's completely irrelevant, the build machine's newline handling can
be whatever, as the content hash doesn't
need to be the same on different machines.

Relying on a mandatory content hash is DoA. Builds using header guards
are much faster than that.

And not relying on a content hash doesn't work, because filesystem
metadata cannot detect same-file
reliably. This duck is dead, and has always been dead.

Received on 2024-09-23 08:04:37