C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Revising #pragma once

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 23 Sep 2024 08:59:32 +0100
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.

A few other things to consider:
(1) Should we allow the header file to have any contents before "#pragma once" ?
(2) Should it be possible to have "#pragma once" more than once in any
given header file ?
(3) Should it be possible to have "#pragma once" in the original
source file (i.e. what happens if the preprocessor encounters "#pragma
once" when it is not in the process of including a header file?) ?

Received on 2024-09-23 07:59:44