[Development] Using '#pragma once' instead of include guards?

Ville Voutilainen ville.voutilainen at gmail.com
Mon Nov 7 11:01:27 CET 2022


On Mon, 10 Oct 2022 at 13:13, Hasselmann Mathias
<mathias at taschenorakel.de> wrote:
>
> I am surprised by the question: "It's non-standard and it's behavior is
> undefined" actually should be enough to avoid such feature.
>
> Actually if a reliable implementation of "#pragma once" would be
> possible, that feature would have been included in the C++ standard for
> a long time already, wouldn't it?

Oh, there is a reliable implementation, no problem there. :D It's
called "hash the file contents". Various
implementations have different modes of operation where they
desperately try to avoid doing that,
or do that just partially. The last time standardizing a "#once" was
discussed in the standard
committee was 2012, and compiler vendors' feedback killed the idea
dead, and it hasn't come
back since. We have spent our energy standardizing modules instead.

The C committee has been recently considering standardizing a "#once".
It has been attempted
to make them aware of the compiler vendor feedback on the C++ side of things.

It will be a glorious day when we stop doing textual inclusion, and
don't need to talk about its myriad problems
any more.


More information about the Development mailing list