[Development] Using #pragma once
Thiago Macieira
thiago.macieira at intel.com
Mon Oct 8 17:33:00 CEST 2018
On Monday, 8 October 2018 01:50:04 PDT Edward Welbourne wrote:
> 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 ?
THAT is the million dollar question.
Of course it shouldn't, but it could happen in an improperly-configured build,
with stale files. And now instead of no error due to same include guard, you
get C++ error which make no sense.
> 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 ability to debug and who has to do it.
If this problem happens, it happens for someone *using* Qt, not those of us
developing it. And figuring out what went wrong is extremely difficult.
> The other reasons make more sense to me (and I'm "not a fan" of #pragma
> in general),
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list