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

Eike Ziller Eike.Ziller at qt.io
Mon Oct 10 12:07:49 CEST 2022


> On 10 Oct 2022, at 11:55, Volker Hilsheimer via Development <development at qt-project.org> wrote:
> 
> 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?

Just for reference, we are using it without issues in Qt Creator since 2016.

(But of course our platform and compiler requirements are more restricted than for Qt.)

-- 
Eike Ziller
Principal Software Engineer

The Qt Company GmbH
Erich-Thilo-Straße 10
D-12489 Berlin
eike.ziller at qt.io
http://qt.io
Geschäftsführer: Mika Pälsi,
Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B




More information about the Development mailing list