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

EXT Mitch Curtis mitch.curtis at qt.io
Mon Oct 10 12:16:11 CEST 2022


> -----Original Message-----
> From: Development <development-bounces at qt-project.org> On Behalf Of
> Volker Hilsheimer via Development
> Sent: Monday, 10 October 2022 5:55 PM
> To: development at qt-project.org
> Subject: [Development] Using '#pragma once' instead of include guards?
> 
> 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?

FYI, there was a discussion about this a few years back:

https://lists.qt-project.org/pipermail/development/2018-October/033726.html
 
> 
> 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