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

Hasselmann Mathias mathias at taschenorakel.de
Mon Oct 10 12:11:49 CEST 2022


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?

Ciao
Mathias

Am 10.10.2022 um 11:55 schrieb Volker Hilsheimer via Development:
> Hi,
>
>
> We are using `#pragma once` in a number of examples and tests in the Qt source tree, but I don’t think we have officially endorsed it in favour of explicit include guards.
>
> #pragma once is “non-standard but widely supported” [1], with some caveats, e.g. when there are multiple header files with the same name (which each compiler then handles differently, as there is no standard).
>
>  From what I see, it should in practice be ok to use. But perhaps I’m missing something. Does anything speak against using ‘#pragma once’ in new files?
>
>
> Volker
>
> [1] https://en.wikipedia.org/wiki/Pragma_once
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development


More information about the Development mailing list