Date: Mon, 23 Sep 2024 13:22:17 +0200
This should work the same way as include guards. Once the file is included,
you don't include it second time.
Yes, utils.h may be a different file each time but that's irrelevant.
Hash works 🙂
On Mon, Sep 23, 2024, 12:55 Gašper Ažman via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> HASH DOES NOT WORK. There are reasons for this in this thread, but they
> boil down to this: you'd need to hash the entire reachable filesystem
> because #include's don't resolve the same way depending on where the file
> is accessed from on the filesystem.
>
> #pragma once
> #include "utils.h"
>
> You'll see that header verbatim several times for different libraries in a
> translation unit and you'll miscompile. HASH DOES NOT WORK.
>
> On Mon, Sep 23, 2024 at 10:28 AM Frederick Virchanza Gotham via
> Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>> On Mon, Sep 23, 2024 at 9:04 AM Ville Voutilainen wrote:
>> >
>> > 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.
>>
>>
>> I meant something like the following:
>>
>> Leonardo has his Apple laptop, and he checks out code to
>> \\192.168.1.62\code\project1.
>> Donatello has his MS-Windows laptop, and he checks out code to
>> \\192.168.1.62\code\project2.
>>
>> So Leonardo and Donatello have all of their code checked out to the
>> same network drive.
>>
>> In Donatello's project, he has a source file containing the line:
>>
>> #include "../project1/monkey.hpp"
>>
>> This header file has been checked out by Leonardo with Apple line
>> endings. But Donatello also has his own copy of "monkey.hpp" in his
>> own checkout, and one of Donatello's source files looks like this:
>>
>> #include "../project1/monkey.hpp"
>> #include "common//monkey.hpp"
>>
>> So the first directive gets the header file with "\r\n" line endings,
>> and the second directive gets it with "\n" line endings. And so if
>> we're going to be taking the hash of file contents, I think best to
>> normalise the line endings first (and also to remove trailing new line
>> characters).
>>
>> Taking the hash of file contents might have too great an impact on
>> compile times though. If compile time weren't an issue though, then I
>> think taking the hash of file contents would be the optimal way to do
>> "#pragma once".
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
you don't include it second time.
Yes, utils.h may be a different file each time but that's irrelevant.
Hash works 🙂
On Mon, Sep 23, 2024, 12:55 Gašper Ažman via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> HASH DOES NOT WORK. There are reasons for this in this thread, but they
> boil down to this: you'd need to hash the entire reachable filesystem
> because #include's don't resolve the same way depending on where the file
> is accessed from on the filesystem.
>
> #pragma once
> #include "utils.h"
>
> You'll see that header verbatim several times for different libraries in a
> translation unit and you'll miscompile. HASH DOES NOT WORK.
>
> On Mon, Sep 23, 2024 at 10:28 AM Frederick Virchanza Gotham via
> Std-Proposals <std-proposals_at_[hidden]> wrote:
>
>> On Mon, Sep 23, 2024 at 9:04 AM Ville Voutilainen wrote:
>> >
>> > 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.
>>
>>
>> I meant something like the following:
>>
>> Leonardo has his Apple laptop, and he checks out code to
>> \\192.168.1.62\code\project1.
>> Donatello has his MS-Windows laptop, and he checks out code to
>> \\192.168.1.62\code\project2.
>>
>> So Leonardo and Donatello have all of their code checked out to the
>> same network drive.
>>
>> In Donatello's project, he has a source file containing the line:
>>
>> #include "../project1/monkey.hpp"
>>
>> This header file has been checked out by Leonardo with Apple line
>> endings. But Donatello also has his own copy of "monkey.hpp" in his
>> own checkout, and one of Donatello's source files looks like this:
>>
>> #include "../project1/monkey.hpp"
>> #include "common//monkey.hpp"
>>
>> So the first directive gets the header file with "\r\n" line endings,
>> and the second directive gets it with "\n" line endings. And so if
>> we're going to be taking the hash of file contents, I think best to
>> normalise the line endings first (and also to remove trailing new line
>> characters).
>>
>> Taking the hash of file contents might have too great an impact on
>> compile times though. If compile time weren't an issue though, then I
>> think taking the hash of file contents would be the optimal way to do
>> "#pragma once".
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2024-09-23 11:22:30