[Development] Using #pragma once

Edward Welbourne edward.welbourne at qt.io
Mon Oct 8 10:50:04 CEST 2018


On Sunday, 7 October 2018 01:56:47 PDT Lars Knoll wrote:
>> Just a quick question: Does anybody have any good arguments against
>> us starting to use #pragma once instead of header guards throughout
>> our code base?

Thiago Macieira (7 October 2018 20:39) wrote:
> For example, I have ~/src as a bind-mount to ~/dev/src. That means
>         ~/src/qt/qt5/qtbase/src/corelib/global/qglobal.h
>         ~/dev/src/qt/qt5/qtbase/src/corelib/global/qglobal.h
> are actually the same file, but they aren't for the effects of #pragma
> once because the paths differ.

How could the compiler end up trying to #include both of those files ?
Wherever they appear in its include-path for a given compilation unit,
one of them must appear before the other and thus be used consistently.
I suppose you could put one directory in the sys-include path for
#include <qglobal.h> and the other in the source-include path for
#include "qglobal.h" ... but this seems like a strangely contrived thing
to do and I'd be inclined to say "well don't do that, then" to anyone
who has problems with it.  What am I missing ?

The other reasons make more sense to me (and I'm "not a fan" of #pragma
in general),

	Eddy.



More information about the Development mailing list